在jQuery 1.9中使用事件名称空间时,感叹号在trigger()中不起作用 [英] Exclamation mark doesn't work in trigger() when using event namespace in jQuery 1.9
本文介绍了在jQuery 1.9中使用事件名称空间时,感叹号在trigger()中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码:
$("div").on("click",function(){
console.log("click");
});
$("div").on("click.plugin", function(){
console.log("click.plugin");
});
$("button").click(function() {
$("div").trigger("click!");
});
和HTML:
<div>test.</div>
<button >Trigger event according to namespace</button>
当我在jQuery 1.8.3下运行代码时,它可以工作.当我单击按钮时,它将在控制台中记录click
.
When I run the code under jQuery 1.8.3, it works. When I click button, it logs click
in the console.
但是当我更改为jQuery 1.9.1 时,按下按钮时什么也没有发生.在1.9.1中,感叹号似乎不再起作用.
But when I change to jQuery 1.9.1, nothing happens when I press the button. It seems like the exclamation mark doesn't work anymore in 1.9.1.
我在1.9升级指南中找不到此更改.有人知道为什么吗?
I can't find this change in the 1.9 upgrade guide. Does anybody know why?
推荐答案
使用.$
代替!
$("button").click(function() {
$("div").trigger("click.$");
});
演示 [来源:Tim B James]
这篇关于在jQuery 1.9中使用事件名称空间时,感叹号在trigger()中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文