Focus events: 1. Use the focus() method to set the element to obtain the focus event, the syntax is "$(selector).focus(function)"; 2. Use the blur() method to set the element to lose the focus event, the syntax is is "$(selector).blur(function)".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The focus event occurs when an element gains focus.
When an element is selected by mouse click or positioned by tab key, the element will gain focus.
The focus() method triggers the focus event, or specifies a function to run when the focus event occurs.
The syntax is:
$(selector).focus()
or:
$(selector).focus(function)
The blur event occurs when the element loses focus.
blur() method triggers the blur event, or specifies a function to run when the blur event occurs.
The syntax is:
$(selector).blur()
or:
$(selector).blur(function)
The example is as follows:
Output result:
Related recommendations:javascript learning tutorial
The above is the detailed content of What is javascript focus event. For more information, please follow other related articles on the PHP Chinese website!