Home > Web Front-end > JS Tutorial > body text

Code to control carriage return event using JS_javascript skills

WBOY
Release: 2016-05-16 18:10:36
Original
1139 people have browsed it

Our operating habit is indeed to use Enter to submit data directly. After some inspection of the project, it was found that the page was not designed well, which caused the browser to regard the logout button as the default button when loading, so the logout button event was triggered as soon as Enter was pressed. Considering a huge project, it is unrealistic to change the page design for this problem. Moreover, the customer requires that the "Save" button event be triggered when the Enter button is pressed when there is a "Save" button, and it is triggered when there is a "Next" button. Events, when there is a "Submit" button, the corresponding events are triggered, etc. If you change the pages one by one, the workload will be staggering. So I considered using js directly in the template header file to trigger the event of the Enter button in the entire site. The following is the corresponding code:

Copy code The code is as follows:



It’s actually quite simple. Just add the above paragraph to the template file, first get the enter event, then get all the buttons on the page, and cycle through the buttons one by one. Does the ID meet your requirements? If yes, trigger the button event. Another problem with the above code is that when buttons with several IDs exist at the same time on your page, all buttons will be triggered. As for how to improve it, it depends on the actual application scenario, and in my project, they will not exist at the same time. These buttons can be used safely.
Related labels:
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