:[JQ权威指南]第十天:unbind()方法移除元素绑定事件
2015-07-28 14:45
537 查看
unbind()的功能是移除元素绑定的事件,其调用的语法格式如下:
unbind([type],[fn])
其中,参数type为移除的事件类型,fn为需要移除的事件处理函数。如果该方法没有参数,移除所有绑定的时间;如果带有参数type,移除该参数所指定的时间类型;如果带有参数fn,则值移除绑定时候指定的函数fn.
在页面中设置三个按钮,前两个按钮分别执行各自的时间,第三个按钮通过unbind方法移除所绑定的全部事件。即单击第三个按钮后,前两个按钮的事件将不会执行。
unbind([type],[fn])
其中,参数type为移除的事件类型,fn为需要移除的事件处理函数。如果该方法没有参数,移除所有绑定的时间;如果带有参数type,移除该参数所指定的时间类型;如果带有参数fn,则值移除绑定时候指定的函数fn.
在页面中设置三个按钮,前两个按钮分别执行各自的时间,第三个按钮通过unbind方法移除所绑定的全部事件。即单击第三个按钮后,前两个按钮的事件将不会执行。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>移除事件</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="../jquery-2.1.4.js" ></script> <style type="text/css"> body{ font-size:13px} .btn{border:#666 1px solid; padding:2px; width:80px;} div{ line-height:1.8em} </style> <script type="text/javascript"> $(function(){ function oClick(){ $("#divTip").append("<div>按钮二的单击事件</div>"); } $("input:eq(0)").bind("click",function(){ $("#divTip").append("<div>按钮一的单击事件</div>"); }); $("input:eq(1)").bind("click",oClick); $("input:eq(2)").bind("click",function(){ $("input").unbind("click",oClick); $("#divTip").append("<div>按钮二的绑定事件被取消</div>"); }); }) </script> </head> <body> <div> <input id="Button1" type="button" value="按钮一" class="btn"> <input id="Button2" type="button" value="按钮二" class="btn"> <input id="Button3" type="button" value="删除事件" class="btn"> </div> <div id="divTip" style="padding-top:10px"></div> </body> </html> ![这里写图片描述](http://img.blog.csdn.net/20150728144421675)
相关文章推荐
- java设计模式:观察者模式
- SSH商城笔记2
- ListView实现Item上下拖动交换位置 并且实现下拉刷新 上拉加载更多
- android常用UI使用案例:ImageSwitcher和Gallery
- 欢迎使用CSDN-markdown编辑器
- JavaScript中双叹号(!!)作用
- aerospike性能测试
- HDU 2039 三角形
- HTTP Streaming with FFMpeg and an Open Source Segmenter
- Git的深入理解与GitHub托管服务的使用
- Matlab--函数极值最值零点
- 在线聊天室的实现(1)--websocket协议和javascript版的api
- mongodb搭建
- 链表、图的相关算法
- 最近感想
- Matlab--积分微分
- How to Make an iOS VoIP App With Pjsip: Part 5
- windows下tomcat性能优化总结
- WCF的配置文件中的要素
- struts2分页实现