0

我希望让 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');
        });
    }
4

1 回答 1

3

$('{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');
        });
    }
于 2013-03-16T13:42:14.350 回答