更新时间:2022-11-20 10:13:25
嗯,你可以在一些常见的元素上使用自定义事件,例如 document.body
。
Well, you can use custom events on some common element, say document.body
.
// Subscribe
$(document.body).on('nifty.event', function() {
// Handle it
});
// Publish
$(document.body).trigger('nifty.event');
或者完全断开与DOM的连接,有几个pub / sub jQuery插件,像这样一个。
Or for complete disconnection from the DOM, there are a couple of pub/sub jQuery plug-ins, like this one.