当前元素作为其事件函数param [英] The current element as its Event function param
本文介绍了当前元素作为其事件函数param的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个元素
< input type =text>
在此,有一个事件
的onChange = myfunction的(PARAM)。
param是输入本身的内容。我如何处理,当我开火onChange(所以完成字段的更改),这个参数是这个字段的实际值?
是否可能做这样的事情:
onChange =myfunction(document.getElementById('this_id'))
?
解决方案
您可以将 c $ c
myFunction
,这将是输入
< input type =textonChange =myfunction(this)/>
然后 myFunction
可能如下所示: / p>
function myFunction(obj)
{
var value = obj.value; //文本框的值
}
Now, I finally wan't to know, after two weeks search in google.
I've got an element
<input type="text">
On this, there is an Event
onChange="myfunction(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'))"
?
解决方案
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
}
这篇关于当前元素作为其事件函数param的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文