In jsp, how does one automatically submit the form by pressing the Enter key? In jsp, the Return key submits the form
In order to save trouble, you often want to press the Enter key to submit the form. to control these actions, you can use JS to meet the requirements.
The Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <% @ include file = ".. /.. /common/include_tag.jsp "%> <% @ include file = ".. /.. /common/page_var.jsp "%> <! Doctype html>
Solution:
Put the form in a div, and then listen to the div event $ ("# id"). keydown (function (){});
# * # Listen to the carriage return event
Document. onkeydown = function () {if (event. keyCode = 13) {// submit your form $ ('# ff_login'). submit ();}}
# * # Compile js scripts on the page for listening...
# * # Js listens to the enter event #*#
Put the form in a div, and then listen to the div event $ ("# id"). keydown (function (){});
# * # Obtain the focus listener enter #*#
Listen to the keypress event of the entire body. If it is a carriage return key, it will trigger the click Event of the submit button. Of course, there will be related data validation in your click event. If it is not verified, it will not be submitted.
I hope this article will help you with jsp program design.