我有一个元素

<input type="text">

在此,有一个事件
onChange="myfunction(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
}

09-11 01:52
查看更多