我的剧本:

(function($){
$.fn.megaswitcher = function(settings) {
    return this.each(function() {
        var $i = $(this),
            current,
            childs = $i.find('.selection li').length; // returns desired number

        $i.find('.selection li').delegate('.active', 'dblclick', function(e){
            e.preventDefault();
            current = $i.find('.selection li').index(this);
            alert('triggered @ ' + current); // doesn't even execute
            var _delay = $(this).attr('name') > 0 ? (parseInt($(this).attr('name')) * 1000) : 5000;
            $(this).delay(_delay).show(0, function(){
                if((current + 1) < childs){ // if not last
                    $(this).removeClass('active').next().addClass('active').show(0, function(){
                        $i.find('.image img').addClass('tempp');
                        $(this).find('img').clone().hide().addClass('temp').appendTo($i.find('.image')).fadeIn(400, function(){
                            $i.find('.image img.tempp').remove();
                        });
                    }).trigger('dblclick');
                }else{
                    $(this).removeClass('active');
                    $i.find('.selection li:first').addClass('active').show(0, function(){
                        $i.find('.image img').addClass('tempp');
                        $(this).find('img').clone().hide().addClass('temp').appendTo($i.find('.image')).fadeIn(400, function(){
                            $i.find('.image img.tempp').remove();
                        });
                    }).trigger('dblclick');
                }
            });
        });

        $i.find('.selection li.active').trigger('dblclick');
    });
};
})(jQuery);


一定要承认,那真是一团糟,但我不知道为什么那个代表没有工作...

有任何想法吗?

附言我有一个基于dblclick的基于相同技术的不同插件,它可以完美地工作,除了,它不使用find();进行项目选择,而且我感觉是导致问题的原因,但我没有不知道用它来代替它。

提前致谢!

最佳答案

您必须在要附加事件的项目的父项上调用委托。
代替:

$i.find('.selection li').delegate('.active' ...


你应该做

$i.find('.selection').delegate('li.active'

关于javascript - jQuery委托(delegate)不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5607231/

10-11 06:14
查看更多