禁用键盘上的(全局)指定键兼容iE、Chrome、火狐
人气:0
首先你要确定你是要禁用全局的还是指定控件 ,如我只要禁用一个文本框的上下键
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值链接
复制代码 代码如下:
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值链接
加载全部内容