Home  >  Article  >  Web Front-end  >  How to bind the lost focus event to the input box in jquery

How to bind the lost focus event to the input box in jquery

青灯夜游
青灯夜游Original
2022-05-25 17:26:233436browse

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});".

How to bind the lost focus event to the input box in jquery

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>

How to bind the lost focus event to the input box in jquery

[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!

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