Home > Web Front-end > JS Tutorial > How to use JS to block the Enter key in the page to submit the form

How to use JS to block the Enter key in the page to submit the form

高洛峰
Release: 2016-12-05 13:07:53
Original
1208 people have browsed it

For example, when the JS code is set to respond to the Enter key of the

tag to trigger an event, according to the bubbling event principle, the event will be transmitted to the form and the form will be submitted. This is not the effect we want. We can set the following code to block it:

$(document).keydown(function(event){
  switch(event.keyCode){
     case 13:return false;
     }
});
Copy after login

However, if there is a button on the page, the form will also be submitted in the Opera browser. This is because the button is in the generated HTML The code is of submit type. The solution is to set UseSubmitbehavior="false" in the button so that the button is of button type in the HTML code generated on the page.


Related labels:
js
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