我正在将我们的一些代码库从jquery转换而来。直到我们遇到事件,一切都非常顺利。我们有很多带有jquery的命名空间代码,所以对于现在我们不会将trigger
函数调用转换为jquery。但是,我们正在尝试使用js事件侦听器。这是问题的自定义事件:js事件监听器和jquery事件触发器不是朋友
window.addEventListener("testevent", function(e){
console.log("js fired"); // this doesn't log, but it should!
});
$(window).on("testevent", function(e){
console.log("jquery listener fired"); // this logs fine, like it should
});
// trigger the custom event with jQuery
$(window).trigger("testevent");
如果我上面运行控制台,我得到一个日志jQuery的监听器的代码,而不是听众。有谁知道为什么会发生这种情况?
的可能重复的[为什么JQuery的不触发添加事件侦听?](http://stackoverflow.com/questions/14232448/why-jquery-doesnt-trigger-added-eventlistener) – JAAulde