显示单个数字 jQuery .each()

发布于 2024-10-26 02:12:29 字数 499 浏览 2 评论 0原文

有人知道我必须在这个显示单个数字(如“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 英寸。

Anyone know what I must change in this plugin that displaying a single number ( like "1/3" ) ?

http://slidesjs.com

I modified this line:

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

and change to this:

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

and now shows me: "1/3 2/3 3/3".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美不过初阳 2024-11-02 02:12:29

所以...我相信您只想在幻灯片中显示当前页码。因此,如果您放映 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++;
    }
});

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

希望这有帮助,
斯普里诺724

So... I believe you only want to display the current page number in the slideshow. So if you have a show of 5 slides, and you are on page 3, then you will only see "3/5". Correct?

So, answering this question, here is the original loop surrounding the code you posted above.

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

However, to only display the current page we are on, we will need to add a conditional statement to display only the one page...

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++;
    }
});

I'll admit, this code is not at all tested, but it should work. One thing I don't know is if it will automatically update as you scroll through the slides.

Hope this helps,
spryno724

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文