We do like to use carriage return to directly submit data. After some checks on the project, this is actually a poor page design. As a result, the browser regards the exit button as the default button during loading, so the exit button event is triggered when you press Enter. Considering that it is not realistic for a large project to modify the page design for this problem, the customer requires that the "save" button event be triggered when the "save" button is clicked by pressing the enter button, when there is a "Next" button, it will trigger its event, and when there is a "Submit" button, it will trigger the corresponding event, etc. If one page changes, the workload will be amazing. Therefore, we need to use js directly in the template header file to trigger the full-site carriage return button event. The following code is used:
Copy codeThe Code is as follows:
<Script language = "javascript" for = "document" event = "onkeydown">
// Handle the carriage return event
If (event. keyCode = 13 ){
Event. keyCode = 0;
Var list = document. getElementsByTagName ("input ");
For (var I = 0; I <list. length & list [I]; I ++)
{
If (list [I]. id. indexOf ("IBtnNextStep")> 0) {// ID contains a button with the word "IBtnNextStep"
List [I]. click ();
}
If (list [I]. id = "BtnSave "){
List [I]. click ();
}
If (list [I]. id = "BtnSumbit "){
List [I]. click ();
}
}
Return false;
}
</Script>
In fact, it is quite simple to add the above section to the template file. First, obtain the carriage return event, then retrieve all the buttons on the page, and cyclically determine whether the button IDs meet your requirements, yes, trigger the button event. The above code still has a problem: when the buttons with those IDs exist on your page at the same time, all buttons will be triggered. As for how to improve the buttons, it depends on the actual application scenario, in my project, these buttons do not exist at the same time, so they can be applied safely.