jQuery event.namespace 属性
实例
添加和删除自定义命名空间:
<!DOCTYPE html><html><head><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><script>$(document).ready(function(){$("p").on("custom.someNamespace",function(event){alert(event.namespace);});$("p").click(function(event){$(this).trigger("custom.someNamespace");});$("button").click(function(){$("p").off("custom.someNamespace");});});</script></head><body><p>点击这个段落</p><button>删除命名空间</button></body></html>
定义与用法
当事件被触发时,event.namespace 属性返回自定义命名空间。
该属性可被插件作者用来根据所使用的命名空间以不同的方式处理任务。
提示:对于 jQuery 而言,以下划线开始的命名空间会被保留。
语法
event.namespace
| 参数 | 描述 |
|---|---|
| event | 必填。 event 参数来自事件绑定函数 |