使用jquery导入“next”内容

时间:2022-02-14 00:31:34

I'm trying to add a 'next' button to my content rotation. The content for each slide are on subpages. It works to click on each slides actual nav link, but the 'next' link won't pull in the content I need.

我想在我的内容旋转中添加一个“next”按钮。每张幻灯片的内容都在子页面上。点击每个幻灯片上的导航链接是可行的,但是“下一个”链接不会显示我需要的内容。

HTML

HTML

<ul class="navtop">
    <li class="selected"><a href="slide-01.html">1</a></li>
    <li><a href="slide-02.html">2</a></li>
    <li><a href="slide-03.html">3</a></li>
    <li><a href="slide-04.html">4</a></li>
</ul>

JS

JS

$('a.next').click(function() {
    var nexthref = $('.navsub li.selected a').href;
    //remove and add selected class
    var next = $('.navsub li.selected').next('li');
    $('.navsub li.selected').removeClass('selected');
    $(next).addClass('selected');

    //fade out and fade in      
    $('.pull div').fadeOut('slow', function(){
            var current = $('.navsub li.selected a');           
            $(current).load(nexthref + " .pullSource div", function(){
                    $(this).fadeIn('slow');
            });

        });
    return false;


});

In firebug is says the nexthref is undefined; am I putting that var in the wrong place? Where should it be?

在firebug中,是说nexthref没有定义;我把var放在错误的地方了吗?应该是在哪里?

Thank-you.

感谢。

2 个解决方案

#1


4  

var nexthref = $('.navsub li.selected a').attr('href');

now it'll take me a minute or two to figure out if there's anything else wrong ...

现在我要花一两分钟才能弄清楚还有什么地方不对劲……

edit — I'm not clear on where the <a> ever gets the "next" class set. I see the "selected" class, but not "next". Does some other code do that?

编辑——我不清楚在哪里获得了“下一个”类集。我看到的是“选定”类,但不是“下一个”类。还有其他的代码吗?

#2


0  

Thanks, figured it out.

谢谢,问题解决了。

$('a.next').click(function() {      
    //remove and add selected class
    var next = $('.navsub li.selected').next('li');
    $('.navsub li.selected').removeClass('selected');
    $(next).addClass('selected');

    //fade out and fade in  
    var nexthref = $('.navsub li.selected a').attr('href');
    $('.pull div').fadeOut('slow', function(){
            var current = $('.navsub li.selected a');           
            $(this).load(nexthref + " .pullSource div", function(){
                    $(this).fadeIn('slow');
            });

        });
    return false;


});

#1


4  

var nexthref = $('.navsub li.selected a').attr('href');

now it'll take me a minute or two to figure out if there's anything else wrong ...

现在我要花一两分钟才能弄清楚还有什么地方不对劲……

edit — I'm not clear on where the <a> ever gets the "next" class set. I see the "selected" class, but not "next". Does some other code do that?

编辑——我不清楚在哪里获得了“下一个”类集。我看到的是“选定”类,但不是“下一个”类。还有其他的代码吗?

#2


0  

Thanks, figured it out.

谢谢,问题解决了。

$('a.next').click(function() {      
    //remove and add selected class
    var next = $('.navsub li.selected').next('li');
    $('.navsub li.selected').removeClass('selected');
    $(next).addClass('selected');

    //fade out and fade in  
    var nexthref = $('.navsub li.selected a').attr('href');
    $('.pull div').fadeOut('slow', function(){
            var current = $('.navsub li.selected a');           
            $(this).load(nexthref + " .pullSource div", function(){
                    $(this).fadeIn('slow');
            });

        });
    return false;


});