The "blur" event is triggered when the element loses focus. In jquery, you can use the blur() method to set the event processing function that needs to be run when the "blur" event is triggered. The syntax is "$(selector).blur(function)"; the processing function can specify the code to be executed when the blur event occurs. .
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, the "blur
" event is triggered when an element loses focus.
You can use the blur() method to set the event processing function that needs to be run when the "blur" event is triggered; this function can also specify the code to be executed when the blur event occurs.
Syntax:
$(selector).blur(function)
Parameters | Description |
---|---|
function | Optional. Specifies the function to run when the blur event occurs. |
Example: Change the color of the input field when it loses focus (blur)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("input").focus(function() { $("input").css("background-color", "#FFFFCC"); }); $("input").blur(function() { $("input").css("background-color", "#D6D6FF"); }); }); </script> </head> <body> 用户名: <input type="text" /> <p>请在上面的输入域中点击,使其获得焦点,然后在输入域外面点击,使其失去焦点。</p> </body> </html>
[Recommended learning:jQuery video tutorial、web front-end introductory video】
The above is the detailed content of What event is triggered when an element loses focus in jquery. For more information, please follow other related articles on the PHP Chinese website!