使用 jquery 拉入“下一个”内容

Posted

技术标签:

【中文标题】使用 jquery 拉入“下一个”内容【英文标题】:Use jquery to pull in the 'next' content 【发布时间】:2011-04-02 19:16:04 【问题描述】:

我正在尝试将“下一步”按钮添加到我的内容轮播中。每张幻灯片的内容都在子页面上。它可以点击每张幻灯片的实际导航链接,但“下一个”链接不会拉入我需要的内容。

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

$('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;


);

在 firebug 中说 nexthref 是未定义的;我把那个 var 放在错误的地方了吗?它应该在哪里?

谢谢。

【问题讨论】:

【参考方案1】:

谢谢,想通了。

$('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;


);

【讨论】:

【参考方案2】:
var nexthref = $('.navsub li.selected a').attr('href');

现在我需要一两分钟才能弄清楚是否还有其他问题......

edit — 我不清楚 &lt;a&gt; 在哪里获得了“下一个”类集。我看到“选定”类,但没有看到“下一个”。其他代码可以做到这一点吗?

【讨论】:

下一个类是在ul末尾手动添加的链接。它在列表之后有 Next。谢谢!

以上是关于使用 jquery 拉入“下一个”内容的主要内容,如果未能解决你的问题,请参考以下文章

通过 JavaScript 或 jQuery 停止在 hashchange 事件上加载图像

将内容拉入 td data-label 属性

使用查询拉入重复项

将特定的 XML 节点拉入 HTML 文档

如何将 CMS 页面的内容拉入静态块?

您可以将 API 调用直接拉入 Pandas Dataframe 吗?