当前元素作为其Event函数参数

Flo*_*ler 7 javascript dom

我有一个元素

<input type="text">
Run Code Online (Sandbox Code Playgroud)

在这方面,有一个事件

onChange="myfunction(param)".
Run Code Online (Sandbox Code Playgroud)

"param"是输入本身的内容.我如何处理,当我触发onChange(如此完成字段的更改)时,在此参数中该字段的实际值是多少?

有可能做这样的事情:

onChange="myfunction(document.getElementById('this_id'))"
Run Code Online (Sandbox Code Playgroud)

hun*_*ter 22

你可以传递thismyFunction哪个input

<input type="text" onChange="myfunction(this)" />
Run Code Online (Sandbox Code Playgroud)

那么myFunction看起来像这样:

function myFunction(obj)
{
    var value = obj.value; // the value of the textbox
}
Run Code Online (Sandbox Code Playgroud)