$(document).ready(function () {
$("form").bind("keypress", function (e) {
var c = e.which ? e.which : e.keyCode;
if (c == 13 || c == 10) {
return false;
}
});
});我用JQuery刪除了所有用戶的 Enter 鍵盤按鈕,目的要把所有 textbox 不可按 enter,但不幸地的,我有一個 textbox 是用多行方式去輸入,這個 textbox 目前已被以上代碼阻了按 Enter,有沒有方式可把這個 textbox 取消,即是可以按 enter?
$("form").bind("keypress", function (e) {
var c = e.which ? e.which : e.keyCode;
if (c == 13 || c == 10) {
return false;
}
});
});我用JQuery刪除了所有用戶的 Enter 鍵盤按鈕,目的要把所有 textbox 不可按 enter,但不幸地的,我有一個 textbox 是用多行方式去輸入,這個 textbox 目前已被以上代碼阻了按 Enter,有沒有方式可把這個 textbox 取消,即是可以按 enter?
http://stackoverflow.com/questions/2525464/is-there-way-to-extend-jquery-to-handle-a-custom-enter-key-event
如果不行重新给textbox绑定事件
$("textbox").bind("keypress")
$("form input[type=text]").not("#textbox1").bind("keypress", function (e) {
var c = e.which ? e.which : e.keyCode;
if (c == 13 || c == 10) {
return false;
}
});
});二、var id="#textbox1";
$(document).ready(function () {
$("form input[type=text]").bind("keypress", function (e) {
var c = e.which ? e.which : e.keyCode;
if ((c == 13 || c == 10) && this.id!=id) {
return false;
}
});
});三、先绑定事件,再取消
$("#textbox1").unbind("keypress");