Tell a programmer to see the background of the front series of tutorials (57) - jQuery event binding and processing


Complete C language self-study manual (33)

Android multi-resolution framework for adaptation

JavaWeb core technology tutorial series

HTML5 front-end development combat tutorial series

MySQL database gymnastics tutorials (35 graphical version)

And overthrow their own past - Custom View tutorial series (10)

Thinking out of the woods, set foot on the road --Android develop sophisticated Advanced essence record

Android programmers looking to tell the front tutorial series (40 episodes free video tutorials + source code)


Copyright Notice

  • This article original author: Columbia Valley's younger brother
  • On the blog address: http: //blog.csdn.net/lfdfhl

In this tutorial, we focus on a common framework jQuery event binding and processing.

jQuery event binding standard

The syntax is as follows:

jQuery对象.事件方法(回调函数);

Examples are as follows:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>jQuery事件绑定及其处理1</title>
		<!--引入jquery文件 -->
		<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function() {
				//点击事件
				$("#blog").click(function () {
					alert("click");
				});
				//鼠标移入事件
				$("#welcome").mouseover(function () {
					alert("mouseover");
				});
				//鼠标移出事件
				$("#welcome").mouseout(function () {
					alert("mouseout");
				});
				
				//事件处理的链式写法
				$("#bye").mouseover(function () {
					alert("mouseover");
				}).mouseout(function () {
					alert("mouseout");
				});
				
			});
		</script>
	</head>
	<body>
		<h2 id="author" style="color: red;">本文作者:谷哥的小弟</h2>
		<h2 id="blog" style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
		<div id="welcome" style="width: 200px;height:200px;background-color:greenyellow">Hello jQuery</div>
		<div id="bye" style="width: 200px;height:200px;background-color:seagreen">Bye JavaScript</div>
	</body>
</html>

Here Insert Picture Description

Use on and off tie binding settlement

The syntax is as follows:

jQuery对象.on("事件名称",回调函数);
jQuery对象.off("事件名称");

Examples are as follows:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>jQuery事件绑定及其处理2</title>
		<!--引入jquery文件 -->
		<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function() {
				//利用on绑定点击事件
				$("#welcome").on("click",function () {
					alert("welcome clicked");
				});
				
				$("#bye").on("click",function () {
					//利用off解除点击事件的绑定
					$("#welcome").off("click");
				});
				
			});
		</script>
	</head>
	<body>
		<h2 id="author" style="color: red;">本文作者:谷哥的小弟</h2>
		<h2 id="blog" style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
		<div id="welcome" style="width: 200px;height:200px;background-color:greenyellow">Hello jQuery</div>
		<div id="bye" style="width: 200px;height:200px;background-color:seagreen">Bye JavaScript</div>
	</body>
</html>

Using the bind and unbind bound tied reconciliation

The syntax is as follows:

jQuery对象.bind("事件名称",回调函数);
jQuery对象.unbind("事件名称");

Examples are as follows:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>jQuery事件绑定及其处理3</title>
		<!--引入jquery文件 -->
		<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function() {
				//利用bind绑定点击事件
				$("#welcome").bind("click",function () {
					alert("welcome clicked");
				});
				
				$("#bye").on("click",function () {
					//利用unbind解除点击事件的绑定
					$("#welcome").unbind("click");
				});
				
			});
		</script>
	</head>
	<body>
		<h2 id="author" style="color: red;">本文作者:谷哥的小弟</h2>
		<h2 id="blog" style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
		<div id="welcome" style="width: 200px;height:200px;background-color:greenyellow">Hello jQuery</div>
		<div id="bye" style="width: 200px;height:200px;background-color:seagreen">Bye JavaScript</div>
	</body>
</html>
Released 1022 original articles · won praise 1986 · Views 2.38 million +

Guess you like

Origin blog.csdn.net/lfdfhl/article/details/102660199