Home > Web Front-end > Front-end Q&A > What event is triggered when an element loses focus in jquery

What event is triggered when an element loses focus in jquery

青灯夜游
Release: 2022-06-07 17:04:34
Original
4620 people have browsed it

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

What event is triggered when an element loses focus in jquery

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)
Copy after login
ParametersDescription
functionOptional. 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>
Copy after login

What event is triggered when an element loses focus in jquery

[Recommended learning:jQuery video tutorialweb 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template