jQuery在插件中查找和binidng

jQuery在插件中查找和binidng,jquery,Jquery,我想我不理解jQuery的行为,在我的插件中,我想处理滑动控件的点击事件,使用find函数它不起作用,当我直接抓取元素时,一切都很好 jQuery.fn.whoscheering = (function () { var el = $(this), left = el.find('.nav-prev'), right = el.find('.nav-next'), bubble; // this doesn't work left.bind("c

我想我不理解jQuery的行为,在我的插件中,我想处理滑动控件的点击事件,使用find函数它不起作用,当我直接抓取元素时,一切都很好

jQuery.fn.whoscheering = (function () {
    var el = $(this),
    left = el.find('.nav-prev'),
    right = el.find('.nav-next'),
    bubble;

    // this doesn't work
    left.bind("click", function (e) {
        console.log('left');
        e.preventDefault();
    });

    // below works!
    $('.nav-prev').bind('click', function (e) {
        console.log(e);
        e.preventDefault();
    });
});

您在插件中使用的是自开票功能,它应该是:

jQuery.fn.whoscheering = function () {
   ---
};
不是:

如果
.find()
不起作用,
.nav prev
.nav next
可能不在初始化插件的元素中。在插件中,
这个
是jQuery对象:

jQuery.fn.whoscheering = function () {
    var left  = this.find('.nav-prev'),
        right = this.find('.nav-next'),
        bubble;

    left.on('click', function (e) {
        e.preventDefault();
        console.log('left');
    });
};

jQuery.fn.whoscheering = function () {
    var left  = this.find('.nav-prev'),
        right = this.find('.nav-next'),
        bubble;

    left.on('click', function (e) {
        e.preventDefault();
        console.log('left');
    });
};