的什么,我试图做一个简化的版本如下:jQuery的全球监听自定义事件
var indication = $('#some-div');
indication.bind('custom-event', function() { ... }
// ... later on!
function OtherThing() {
$(this).trigger('custom-event');
}
我想indication.bind('custom-event')
从function OtherThing
接收触发无两有明确了解彼此。这可能吗?到目前为止,我唯一的解决方案是将监听器和事件绑定到body ...这看起来很sl - - 有没有更好的方法?
什么你的意思是“没有两个人必须明确地彼此了解”? – 2012-03-20 17:53:01
@RobW - 不知道如何进一步解释它,然后阅读代码...我知道我可以将'$(this).trigger'改成'$('#some-div).trigger'并让它工作但是这打破了目的。正如我所说我现在的解决方案是将监听器和发射器绑定到'$('body')' – Will 2012-03-20 17:56:34