The example of this article summarizes the JavaScript implementation of the Enter key submission form method. Share to everyone for your reference. The specific analysis is as follows:
First method: JavaScript implementation
Copy Code code as follows:
<title> JavaScript Implement enter key Submit form </title>
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<script type= "Text/javascript" >
Document.onkeydown = function (EV) {
EV = EV | | window.event;
if (Ev.keycode = = 13) {
Alert ("I'm submitting the form");
}
}
</script>
<body>
</body>
The second approach: jquery implementation (supported by IE8, Chrome, and Firefox)
Copy Code code as follows:
<title> JavaScript Implement enter key Submit form </title>
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<script type= "Text/javascript" src= "Jquery-1.8.2.min.js" ></script>
<script type= "Text/javascript" >
$ (function () {
$ (document). KeyDown (function (e) {
var curkey = E.which;
if (Curkey = = 13) {
Alert ("I'm submitting the form");
}
});
});
</script>
<body>
</body>
I hope this article will help you with the Web design based on JS.