编辑Nivo Slider,将.live更改为.on

时间:2013-03-16 13:33:47

标签: jquery nivo-slider

我希望Nivo滑块能够使用最新版本的jQuery。我需要将.live更改为.on以使其工作,但直接交换不起作用。如何使其适用于jQuery 1.9?

if(settings.directionNav){
        slider.append('<div class="nivo-directionNav"><a class="nivo-prevNav">'+ settings.prevText +'</a><a class="nivo-nextNav">'+ settings.nextText +'</a></div>');

        $('a.nivo-prevNav', slider).live('click', function(){
            if(vars.running) { return false; }
            clearInterval(timer);
            timer = '';
            vars.currentSlide -= 2;
            nivoRun(slider, kids, settings, 'prev');
        });

        $('a.nivo-nextNav', slider).live('click', function(){
            if(vars.running) { return false; }
            clearInterval(timer);
            timer = '';
            nivoRun(slider, kids, settings, 'next');
        });
    }

1 个答案:

答案 0 :(得分:2)

$('{element_identifier'}).live(fn)相当于$(document).on('evt', '{element_identifier}', fn),所以这是我要做的交换:

if(settings.directionNav){
        slider.append('<div class="nivo-directionNav"><a class="nivo-prevNav">'+ settings.prevText +'</a><a class="nivo-nextNav">'+ settings.nextText +'</a></div>');

        $(document).on('click', 'a.nivo-prevNav, a.nivo-directionNav', function(){
            if(vars.running) { return false; }
            clearInterval(timer);
            timer = '';
            vars.currentSlide -= 2;
            nivoRun(slider, kids, settings, 'prev');
        });

        $(document).on('click', 'a.nivo-nextNav', function(){
            if(vars.running) { return false; }
            clearInterval(timer);
            timer = '';
            nivoRun(slider, kids, settings, 'next');
        });
    }