【发布时间】:2013-12-22 09:41:00
【问题描述】:
我几乎有这个定义插件实例的代码:
$.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 次,还是只调用了一次?
【问题讨论】:
标签: javascript jquery html events plugins