当前元素作为其事件函数参数 [英] The current element as its Event function param
本文介绍了当前元素作为其事件函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个元素
<input type="text">
关于这个,有一个事件
onChange="myfunction(param)".
"param" 是输入本身的内容.我该如何处理,当我触发 onChange(因此完成字段的更改)时,此 param 中是此字段的实际值?
"param" is the content of the input itself. How can I handle, that, when I fire onChange (so complete the change of the field), in this param is the actual value of this field?
是否可以做这样的事情:
Is it possible to do something like that:
onChange="myfunction(document.getElementById('this_id'))"
推荐答案
您可以将 this
传递给 myFunction
,后者将成为 input
You can pass this
to myFunction
which will be the input
<input type="text" onChange="myfunction(this)" />
然后 myFunction
可能看起来像这样:
then myFunction
could look like this:
function myFunction(obj)
{
var value = obj.value; // the value of the textbox
}
这篇关于当前元素作为其事件函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文