Home  >  Article  >  Web Front-end  >  How to write the lost focus event of input input box using jquery

How to write the lost focus event of input input box using jquery

coldplay.xixi
coldplay.xixiOriginal
2020-12-03 15:16:4312055browse

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.

How to write the lost focus event of input input box using jquery

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.

How to write the lost focus event of input input box using jquery

2. In the test.html file, within the p tag, use the input tag to create an input box.

How to write the lost focus event of input input box using jquery

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.

How to write the lost focus event of input input box using jquery

4. In the test.html file, in the js tag, use the ready() method to execute the function function when the page is loaded.

How to write the lost focus event of input input box using jquery

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.

How to write the lost focus event of input input box using jquery

#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".

How to write the lost focus event of input input box using jquery

7. Open the test.html file in the browser to check the effect.

How to write the lost focus event of input input box using jquery

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!

Statement:
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