ما هو الخطأ في وظيفة مسج هذه، مساعدة
-
19-09-2019 - |
سؤال
$(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");
});
});
لا تنتمي إلى StackOverflow