Home > Web Front-end > JS Tutorial > body text

How to trigger change event in jquery

青灯夜游
Release: 2021-11-19 11:16:43
Original
4546 people have browsed it

In jquery, you can use the change() method to trigger a change event, the syntax "$(selector).change()"; this method can also specify the function to be run when a change event occurs, the syntax "$ (selector).change(function)".

How to trigger change event in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

The change event occurs when the value of an element changes. This event only applies to text fields, and textarea and select elements.

If you want to manually trigger the change event, you need to use the change() method, and this method can also specify the function to be run when the change event occurs.

Syntax for triggering change events

$(selector).change()
Copy after login

Syntax for binding functions to change events

$(selector).change(function)
Copy after login
  • function Optional. Specifies the function to run when the change event occurs.

Example:

<!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() {
				$(".field").change(function() {
					$(this).css("background-color", "#FFFFCC");
				});
				$("button").click(function() {
					$("input").change();
				});
			});
		</script>
	</head>
	<body>
		<button>激活文本域的 change 事件</button>
		<p>用户名: <input class="field" type="text" /></p>
	</body>
</html>
Copy after login

How to trigger change event in jquery

Related video tutorial recommendation: jQuery Tutorial( video)

The above is the detailed content of How to trigger change event 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