将 "on click" 功能扩展为点击。'something'?
Extending "on click" function as click.'something'?
我在我正在使用的 wordpress 主题中找到了下面的代码。我试图理解 click.testClick 语句中代码 "testClick" 的用法。如果我删除它,它的工作原理是一样的。它有什么用吗?
站点中的任何地方都不存在 testClick 词。
这可能是一个可以用来扩展功能的触发器吗?有人可以指出我在这方面的一些文档,或者提供它的使用示例吗?我还是 jquery 的新手。
<a href="#" class="test_click">Test Click</a>
jQuery(document).ready(function(e) {
e( "body" ).on( "click.testClick", ".test_click", function() {
alert("clicked!");
})
});
就像
一样工作
jQuery(document).ready(function(e) {
e( "body" ).on( "click", ".test_click", function() {
alert("clicked!");
})
});
这是一个 event namespace。事件命名空间允许您删除事件侦听器而无需删除元素上的所有事件侦听器:
An event name can be qualified by event namespaces that simplify
removing or triggering the event. For example, "click.myPlugin.simple"
defines both the myPlugin and simple namespaces for this particular
click event. A click event handler attached via that string could be
removed with .off("click.myPlugin") or .off("click.simple") without
disturbing other click handlers attached to the elements. Namespaces
are similar to CSS classes in that they are not hierarchical; only one
name needs to match. Namespaces beginning with an underscore are
reserved for jQuery's use. This will likely be used primarily by plugin authors who wish to handle tasks differently depending on the event namespace used.
示例:
<button>display event.namespace</button>
<p></p>
<script>
$( "p" ).on( "test.something", function( event ) {
alert( event.namespace );
});
$( "button" ).click(function( event ) {
$( "p" ).trigger( "test.something" );
});
</script>
我在我正在使用的 wordpress 主题中找到了下面的代码。我试图理解 click.testClick 语句中代码 "testClick" 的用法。如果我删除它,它的工作原理是一样的。它有什么用吗? 站点中的任何地方都不存在 testClick 词。
这可能是一个可以用来扩展功能的触发器吗?有人可以指出我在这方面的一些文档,或者提供它的使用示例吗?我还是 jquery 的新手。
<a href="#" class="test_click">Test Click</a>
jQuery(document).ready(function(e) {
e( "body" ).on( "click.testClick", ".test_click", function() {
alert("clicked!");
})
});
就像
一样工作jQuery(document).ready(function(e) {
e( "body" ).on( "click", ".test_click", function() {
alert("clicked!");
})
});
这是一个 event namespace。事件命名空间允许您删除事件侦听器而无需删除元素上的所有事件侦听器:
An event name can be qualified by event namespaces that simplify removing or triggering the event. For example, "click.myPlugin.simple" defines both the myPlugin and simple namespaces for this particular click event. A click event handler attached via that string could be removed with .off("click.myPlugin") or .off("click.simple") without disturbing other click handlers attached to the elements. Namespaces are similar to CSS classes in that they are not hierarchical; only one name needs to match. Namespaces beginning with an underscore are reserved for jQuery's use. This will likely be used primarily by plugin authors who wish to handle tasks differently depending on the event namespace used.
示例:
<button>display event.namespace</button>
<p></p>
<script>
$( "p" ).on( "test.something", function( event ) {
alert( event.namespace );
});
$( "button" ).click(function( event ) {
$( "p" ).trigger( "test.something" );
});
</script>