0
當按下Enter鍵時,下面的代碼應該點擊一個button
,如果有其他鍵被點擊,則清空另一個textbox
。檢查鍵碼返回undefined
我無法檢查keycode
,因爲keycode
始終爲undefined
。
$('#txtSearch').keyup(function (e) {
if (e.keycode != 13)
$('#txtId').val("");
else
$('#BtnGo').click();
})
這將幫助你http://stackoverflow.com/questions/302122/jquery-event-keypress-which-key-was-pressed?answertab=acti ve#tab-top –
你必須嘗試'e.which' –
注意它是'keyCode' - 區分大小寫。你也應該使用'e.which'來完全支持跨瀏覽器:'if((e.which || e.keyCode)!= 13)' –