Home  >  Article  >  Web Front-end  >  Usage examples of jQuery unbind()

Usage examples of jQuery unbind()

巴扎黑
巴扎黑Original
2017-06-25 15:15:121014browse

The unbind() method in jQuery is the reverse operation of the bind() method, removing the bound event from each matching element.

Syntax structure:

unbind([type][, data]);


type is the event type, and data is the event to be removed. The specific instructions are as follows:

1. If there are no parameters, all binding events will be deleted;

2. If the event type (type) is provided as a parameter, only the bindings of this type will be deleted. Certain events;

3. If the processing function passed when binding is used as the second parameter, only this specific event processing function will be deleted.

Please see the example below:

<script src="http://www.gamejzy.com/js/jquery.js" type="text/javascript"></script>
<style>
.info {
	background:#ffff66;
}
</style>
<input type="button" id="btn" value="点击我" /> <input type="button" id="delAll" value="删除全部绑定函数" /> <input type="button" id="delFun2" value="删除第二个绑定函数" /><br />
<p class="info"></p>
<script type="text/javascript">
$(document).ready(function(){
	// 为id为btn的按钮添加绑定事件
	$("#btn").bind(&#39;click&#39;, fun1=function(){
		$(".info").append(&#39;<p>绑定函数1</p>&#39;);
	}).bind(&#39;click&#39;, fun2=function(){
		$(".info").append(&#39;<p>绑定函数2</p>&#39;);
	}).bind(&#39;click&#39;, fun3=function(){
		$(".info").append(&#39;<p>绑定函数3</p>&#39;);
	})
	$("#delAll").bind(&#39;click&#39;, function(){
		$("#btn").unbind(); //删除全部绑定事件
	})
	$("#delFun2").bind(&#39;click&#39;, function(){
		$("#btn").unbind(&#39;click&#39;, fun2);  //删除第二个绑定函数
	})
})
</script>


Effect display:


The above is the detailed content of Usage examples of jQuery unbind(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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