取消方法:1、利用off()函数,该函数可移除通过on()添加的事件处理程序,语法“绑定了事件的元素.off()”;2、利用unbind()函数,该函数可删除任意jq方法添加的事件处理程序,语法“绑定了事件的元素.unbind();”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery取消on()绑定的事件
方法1:使用off() 函数
off() 函数通常用于移除通过 on() 方法添加的事件处理程序。
html>
<meta><script></script><script>
$(document).ready(function() {
$("p").on("click", function() {
$(this).slideToggle();
});
$("button").click(function() {
$("p").off();
});
});
</script><p>这是一个段落。</p>
<p>这是另一个段落。</p>
<p>点击任何段落可以令其消失。包括本段落。</p>
<button>移除on()添加的事件</button>

2、使用unbind() 函数
jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
unbind() 函数移除被选元素的事件处理程序。
ubind() 适用于任何通过 jQuery 附加的事件处理程序。
html>
<meta><script></script><script>
$(document).ready(function() {
$("p").on("click", function() {
$(this).slideToggle();
});
$("button").click(function() {
$("p").unbind();
});
});
</script><p>这是一个段落。</p>
<p>这是另一个段落。</p>
<p>点击任何段落可以令其消失。包括本段落。</p>
<button>移除 on()添加的事件</button>

【推荐学习:jQuery视频教程、web前端视频】










