我这就这段代码定义插件实例:功能jQuery插件里面调用
$.fn.someplugin = function(opts) {
$(document).on('click', '.option-1', function() {
alert(1);
});
};
我使用一些代码,这样一个让我的插件工作:
$('.selector-1').someplugin();
所以在jQuery的这种方式将可能的一个点击事件监听器绑定到文档。
问题是,当我多次使用插件时,这是否意味着jQuery将10个单击事件绑定到文档?
$('.selector-1').someplugin();
$('.selector-2').someplugin();
$('.selector-3').someplugin();
$('.selector-4').someplugin();
$('.selector-5').someplugin();
$('.selector-6').someplugin();
$('.selector-7').someplugin();
$('.selector-8').someplugin();
$('.selector-9').someplugin();
$('.selector-10').someplugin();
通过这种方式,它绑定了10个点击监听器 - 因为fn.someplugin被调用了10次,或者只是一个?
该死的,这是非常糟糕的。 – Jasper
@Steve为什么它真的很糟糕?你能指望什么? –
我想尽量减少事件处理程序,因为我的页面上可能会有超过200个插件调用。当时性能开始下滑。 – Jasper