Completa lenguaje C manual de auto-estudio (33)
Android marco multi-resolución para la adaptación
serie de tutoriales de tecnología de núcleo JavaWeb
serie de tutoriales de combate desarrollo front-end HTML5
MySQL base de datos de gimnasia tutoriales (35) versión gráfica
Y derrocar a su propio pasado - Vista personalizada serie de tutoriales (10)
derechos de autor
- Este autor original del artículo: Columbia Valley es el hermano menor
- En la dirección del blog: http: //blog.csdn.net/lfdfhl
En este tutorial, nos centramos en un evento común framework jQuery vinculante y procesar.
norma vinculante evento jQuery
La sintaxis es la siguiente:
jQuery对象.事件方法(回调函数);
Ejemplos son los siguientes:
<!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>
Usar dentro y fuera de la unión del lazo de liquidación
La sintaxis es la siguiente:
jQuery对象.on("事件名称",回调函数);
jQuery对象.off("事件名称");
Ejemplos son los siguientes:
<!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>
Uso de la vinculación y desvinculación reconciliación atado unido
La sintaxis es la siguiente:
jQuery对象.bind("事件名称",回调函数);
jQuery对象.unbind("事件名称");
Ejemplos son los siguientes:
<!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>