您将如何从特定名称空间解除所有jQuery事件的绑定?
要解除与特定命名空间的jQuery事件绑定,请使用unbind()方法。该event.namespace属性用于返回自定义命名空间,当事件被触发。
示例
您可以尝试运行以下代码,以了解事件命名空间的工作方式以及如何从命名空间中取消jQuery事件的绑定-
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").on("custom.myNamespace",function(event){
alert(event.namespace);
});
$("p").click(function(event){
$(this).trigger("custom.myNamespace");
});
$("button").click(function(){
$("p").off("custom.myNamespace");
});
});
</script>
</head>
<body>
<p>Click me</p>
<button>Click the button to remove namespace.</button>
<p>Clicking the above button removes the namespace.</p>
</body>
</html>热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短