对不起,我是JavaScript新手。如何通过单击事件document.getElementById(“someid”)
我想一个ID选择通过作为click事件的参数如下:
我想:
<button onclick="mycustomfunction(document.getElementById('someTextId'))"/>
和使用jquery:
<button onclick="mycustomfunction($('#someTextId').val())"/>
mycustomfunction(control)
{
// do something with the control
}
有人可以帮我了解我要去哪里错了?
为什么不直接在函数中获取id? – jchapa 2013-02-22 21:11:17
为什么需要将该值传递给该函数,因为该值与该实际被点击的元素无关? – 2013-02-22 21:11:26
您传递的元素不是ID,也缺少'function'关键字。 – undefined 2013-02-22 21:11:55