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
WBOYOriginal
2016-05-16 16:47:141471browse
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; }
}
}
};
Statement:
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