Home > Web Front-end > JS Tutorial > Disable Enter key form automatic submission implementation code_javascript skills

Disable Enter key form automatic submission implementation code_javascript skills

WBOY
Release: 2016-05-16 16:47:14
Original
1477 people have browsed it
Copy code The code is as follows:

//Disable the automatic submission of the Enter key form
document.onkeydown = function(event) {
var target, code, tag;
if (!event) {
event = window.event; //For IE browser
target = event.srcElement;
code = event.keyCode;
if (code == 13) {
tag = target.tagName;
if (tag == "TEXTAREA") { return true; }
else { return false; }
}
}
else {
target = event.target; //For browsers that follow w3c standards, such as Firefox
code = event.keyCode;
if (code == 13) {
tag = target.tagName;
if (tag == "INPUT") { return false; }
else { return true; }
}
}
};
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