我有一个元素
<input type="text">
在这上面,有一个事件
onChange="myfunction(param)".
“param”是输入本身的内容。我该如何处理,当我触发 onChange(完成字段的更改)时,此参数中是此字段的实际值?
是否可以这样做:
onChange="myfunction(document.getElementById('this_id'))"
最佳答案
您可以将 this
传递给 myFunction
,这将是 input
<input type="text" onChange="myfunction(this)" />
那么 myFunction
可能如下所示:
function myFunction(obj)
{
var value = obj.value; // the value of the textbox
}
关于javascript - 当前元素作为其事件函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4268085/