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 に答える