The current element as its Event function param

后端 未结 3 1495
無奈伤痛
無奈伤痛 2020-11-30 10:10

I\'ve got an element


On this, there is an Event

onChange=\"myfunction(param)\".
相关标签:
3条回答
  • 2020-11-30 10:48

    To get the .value inline, it would look like this:

    <input type="text" onchange="myfunction(this.value)" />
    
    0 讨论(0)
  • 2020-11-30 11:14

    Inside an inline event handler, this will refer to the DOM element.

    Therefore, you can write onchange="myfunction(this)" to pass the DOM element itself to the function.

    0 讨论(0)
  • 2020-11-30 11:15

    You can pass this to myFunction which will be the input

    <input type="text" onChange="myfunction(this)" />
    

    then myFunction could look like this:

    function myFunction(obj)
    {
        var value = obj.value; // the value of the textbox
    }
    
    0 讨论(0)
提交回复
热议问题