0
$(function() {
    $("table.section thead").click(function() {
      if ($(this).next("table.section tbody").style.display == "block"){
         $(this).next("table.section tbody").slideUp("slow");
      }
      if ($(this).next("table.section tbody").style.display == "none"){
         $(this).next("table.section tbody").slideDown("slow");
      }
    });
});

我不知道如何实现这一点,任何帮助将不胜感激。

更新:

我试图使用以下功能。

$(function() {
    $("table.section thead").click(function() {
    $(this).next("table.section tbody").slideToggle("slow");

    });
});

这给了我一个问题,(当它折叠并单击它时,它会展开然后再次折叠,所以它总是会折叠)。这就是为什么我试图将功能置于顶部。

4

1 回答 1

5

在这种情况下使用可见选择器:

$(function() {
    $("table.section thead").click(function() {
      var body = $(this).next("table.section tbody");
      if (body.is(":visible"))
         body.slideUp("slow");
      else
         body.slideDown("slow");
    });
});

但可能要简单得多,只需.slideToggle()像这样使用:

$(function() {
    $("table.section thead").click(function() {
      $(this).next("table.section tbody").slideToggle("slow");
    });
});
于 2010-03-10T11:20:43.470 回答