显示单个数字jQuery .each()

时间:2011-03-26 00:04:10

标签: jquery pagination numbers each slide

任何人都知道我必须在此插件中更改显示单个数字(例如“1/3”)吗?

http://slidesjs.com

我修改了这一行:

$('.' + option.paginationClass, elem).append('<li><a href="#'+ number +'">'+ (number+1) +'</a></li>');

并改为:

$('.' + option.paginationClass, elem).append('<li><a href="#'+ number +'">'+ (number+1) +'/'+ total +'</a></li>');

现在告诉我:“1/3 2/3 3/3”。

1 个答案:

答案 0 :(得分:0)

所以......我相信你只想在幻灯片中显示当前的页码。因此,如果您有5张幻灯片,并且您在第3页,那么您将只看到“3/5”。正确的吗?

所以,回答这个问题,这是围绕您在上面发布的代码的原始循环。

control.children().each(function(){
    $('.' + option.paginationClass, elem).append('<li><a href="#'+ number +'">'+ (number+1) +'</a></li>');
    number++;
});

但是,要仅显示我们所在的当前页面,我们需要添加条件语句以仅显示一页...

control.children().each(function(){
//Use a conditional statement to display only the current page
//Have jQuery find the slide which is not currently hidden from view
    if ($(this).css('display') == "block") {
        $('.' + option.paginationClass, elem).append('<li><a href="#'+ number +'">'+ (number+1) +'</a></li>');
        return false;
//If the element is not visible we still need to count up, in order to account for this page
    } else {
        number++;
    }
});

我承认,这段代码根本没有经过测试,但应该工作。我不知道的一件事是,当你滚动幻灯片时它会自动更新。

希望这有帮助,
spryno724