给id="a"的按钮绑定输出xxx的事件
<body>
<button id="a">输出</button>
<button id="b">转换</button>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
$("#a").bind("click",function(){
alert("xxx");
});
});
</script>
</body>
取消给id="a"的按钮绑定输出xxx的事件
<body>
<button id="a">输出</button>
<button id="b">转换</button>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
$("#a").bind("click",function(){
alert("xxx");
});
//下面的代码会取消id="a"的按钮绑定的事件
$("#b").click(function(){
$("#a").unbind();
});
});
</script>
</body>
嵌套使用
<body>
<button id="a">输出</button>
<button id="b">转换</button>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
$("#a").bind("click",function(){
alert("xxx");
});
//也可以相互嵌套
$("#b").click(function(){
$("#a").unbind();
$("#a").bind("click",function(){
alert("vvv");
});
});
});
</script>
</body>
请访问https://www.w3school.com.cn/jquery/event_unbind.asp以查找更完整的解决方案