سؤال

$(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");

    });
});

مما يعطيني مشكلة، (عندما ينهار Thead IT وانقر فوقه، فإنه يتوسع ثم ينهار مرة أخرى، لذلك سيكون دائما انهيار). هذا هو السبب في أنني أحاول الحصول على وظيفة في الأعلى.

هل كانت مفيدة؟

المحلول

استخدم المحدد المرئي في هذه الحالة:

$(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");
    });
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top