Home > Article > Web Front-end > How to bind the lost focus event to the input box in jquery
Binding method: 1. Select the input element object, the syntax "$("selector")" will return a jquery object containing the specified element; 2. Use blur() to bind the element object. Focus event, and specify the processing function, the syntax is "element object.blur(function(){//Run code});".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Input box binding in jquery loses focus event
1. Use the selector to select the input element object
Syntax:
$("选择器")
Example$("input")
, you can select all input elements in the document.
Return value: Return the jquery object containing the specified input element
2. Use blur() to bind the focus loss event
Use blur() Bind the lost focus event to the selected input element and specify the event handler to set the code that needs to be run when the event is triggered.
input元素对象.blur(function(){ //运行代码 });
Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function(){ $("input").blur(function(){ alert("输入框失去了焦点"); }); }); </script> </head> <body> 输入你的名字: <input type="text"> <p>在输入框写些东西,然后点击输入框外,让其失去焦点。</p> </body> </html>
[Recommended learning: jQuery video tutorial, web Front-End Video】
The above is the detailed content of How to bind the lost focus event to the input box in jquery. For more information, please follow other related articles on the PHP Chinese website!