Home > Web Front-end > JS Tutorial > Disabling (global) specified keys on the keyboard is compatible with iE, Chrome, and Firefox_javascript tips

Disabling (global) specified keys on the keyboard is compatible with iE, Chrome, and Firefox_javascript tips

WBOY
Release: 2016-05-16 17:33:45
Original
1078 people have browsed it

First you have to determine whether you want to disable global or specific controls. For example, I just want to disable the up and down keys of a text box

Copy code The code is as follows:

NoExec = function(event) {
var k = event.which || event.keyCode;
if (k == 13 || k == 38 | | k == 40) {
if ($("#atWinByArea").attr("id")) {
if (event.which) {//Firefox
event.preventDefault();
} else {//IE, Chrome
event.returnValue = false;
}
}
}
downAt(event);
}
var target = document.getElementById("saytext"); //Specified control Id
if (target.addEventListener) {//Binding listener
target.addEventListener("keydown", NoExec, false);
target.addEventListener("keypress", NoExec, false);
} else if (target.attachEvent) {
target.attachEvent("onkeydown", NoExec);
}

If it is global, just listen to window.keyDown = function(event){.....} Same! ~
The key value link corresponding to the keyboard
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template