jQuery 显示/隐藏以循环浏览表格

标签 jquery animation

我需要设置 jquery 来循环浏览表格,确保它显示/隐藏正确的表格。

基本的 HTML 结构是:

<p><a href="#" class="month-next">Next Month</a></p>

<table class="month-show"><tr><td>blurb</td></tr></table>
<table class="month-hide"><tr><td>blurb</td></tr></table>
<table class="month-hide"><tr><td>blurb</td></tr></table>
<table class="month-hide"><tr><td>blurb</td></tr></table>

等等

到目前为止,在 jQuery 中我有:

$(".month-next").click(function () {
 $("table.month-show").hide();
 HERE I NEED SOME CODE TO ONLY SHOW THE NEXT TABLE IN THE HTML .show();
 return false;
});

最佳答案

$(".month-next").click(function () {
 $("table.month-show").hide().next().show();
 return false;
});

您可能还想更改类,以便下一次调用也能正常工作(编辑:插入 Mark Schultheiss 建议的更改):

$(".month-next").click(function () {
    $("table.month-show")
        .hide()
        .removeClass("month-show")
        .addClass("month-hide")
        .next()
        .show()
        .removeClass("month-hide")
        .addClass("month-show");
    if ($("table").hasClass('month-show').length < 1) {
        $('table').eq(0).addClass('month-show');
    }
 return false;
});

关于jQuery 显示/隐藏以循环浏览表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2334041/

相关文章:

ios - watch 动画

javascript - jqgrid 只允许每行选择一个单元格。执行排序后不工作

javascript - 如何使用JavaScript获取客户端的IP地址?

animation - 创建具有透明背景的 SVG 动画虚线

HTML & CSS 进度条不会停在最后

c# - 移除 Storyboard,使其动画回到原来的状态

javascript - 将对象键值对转换为Javascript中的一系列数组

jquery - bootstrap 3 中的 footable 未初始化

javascript - 打乱所有具有相同类别的标签

ios - 如果我显示 destinationViewController,自定义 Fade Segue 不会设置动画