對不起,我是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