首先你要確定你是要禁用全局的還是指定控件 ,如我只要禁用一個文本框的上下鍵
復制代碼 代碼如下:
NoExec = function(event) {
var k = event.which || event.keyCode;
if (k == 13 || k == 38 || k == 40) {
if ($("#atWinByArea").attr("id")) {
if (event.which) {//火狐
event.preventDefault();
} else {//IE、Chrome
event.returnValue = false;
}
}
}
downAt(event);
}
var target = document.getElementById("saytext"); //指定的的控件Id
if (target.addEventListener) {//綁定監聽
target.addEventListener("keydown", NoExec, false);
target.addEventListener("keypress", NoExec, false);
} else if (target.attachEvent) {
target.attachEvent("onkeydown", NoExec);
}
如果是全局的 就只要監聽window.keyDown = function(event){.....} 一樣一樣的!~
鍵盤所對應的key值鏈接