Disable the Enter key form to automatically submit the implementation code

  • 2020-03-30 03:04:22
  • OfStack

 
//Disable the Enter key form to automatically submit
document.onkeydown = function(event) { 
var target, code, tag; 
if (!event) { 
event = window.event; //For Internet explorer
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 adhere to w3c standards, such as Firefox
code = event.keyCode; 
if (code == 13) { 
tag = target.tagName; 
if (tag == "INPUT") { return false; } 
else { return true; } 
} 
} 
}; 

Related articles: