The input input box uses jquery to lose focus event: first set the id attribute of the input to testid; then use the [ready()] method to execute the function function when the page is loaded; finally use [blur() ] method binds the lost focus event to the input object.
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.
How to use jquery to lose focus event for input input box:
1. Create a new html file, named test.html, to explain how to use jquery for input input box How to write a loss of focus event.
2. In the test.html file, within the p tag, use the input tag to create an input box.
3. In the test.html file, set the id attribute of the input to testid, which is used to obtain the input object through this id below.
4. In the test.html file, in the js tag, use the ready() method to execute the function function when the page is loaded.
5. In the function function, obtain the input object by obtaining the id (testid), and use the blur() method to bind the lost focus event to the input object. When the input input box When the focus is lost, the function function is executed.
#6. In the js tag, in order to verify the focus loss event, in the function function, use the alert() method to input the prompt "input has lost focus".
7. Open the test.html file in the browser to check the effect.
Related free learning recommendations: javascript (video)
The above is the detailed content of How to write the lost focus event of input input box using jquery. For more information, please follow other related articles on the PHP Chinese website!