Home > Article > Web Front-end > Usage examples of jQuery unbind()
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('click', fun1=function(){ $(".info").append('<p>绑定函数1</p>'); }).bind('click', fun2=function(){ $(".info").append('<p>绑定函数2</p>'); }).bind('click', fun3=function(){ $(".info").append('<p>绑定函数3</p>'); }) $("#delAll").bind('click', function(){ $("#btn").unbind(); //删除全部绑定事件 }) $("#delFun2").bind('click', function(){ $("#btn").unbind('click', 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!