Jquery手风琴表应该有活动类切换(Jquery accordion table should have the active class toggled)

编程入门 行业动态 更新时间:2024-10-24 19:26:41
Jquery手风琴表应该有活动类切换(Jquery accordion table should have the active class toggled)

通过单击表我应该在单击的TR上添加一个Active类,并通过关闭它或单击另一个表来删除它。

我错过了什么?

演示: http : //jsfiddle.net/ve3ctfz6/

JS:

$(function () { var $list = $('.table'); $list.find("tr").not('.accordion-wrapper').hide(); $list.find("tr").eq(0).show(); $list.find(".accordion-wrapper").click(function () { $list.find('.accordion-wrapper').not(this).siblings().fadeOut(500); $(this).siblings().fadeToggle(500); $(this).addClass('active'); $list.find('.accordion-wrapper').not(this).removeClass('active'); if ($list.find('.accordion-wrapper').hasClass('active')) { $list.find('.accordion-wrapper').not(this).removeClass('active'); } else if ($(this).is('.active')) { $(this).siblings().fadeToggle(500); $('.active').removeClass('active'); } }); });

By clicking the table I should add a Active class on the clicked TR and able to remove it by closing it or by clicking on another table.

What am I missing?

demo: http://jsfiddle.net/ve3ctfz6/

Js:

$(function () { var $list = $('.table'); $list.find("tr").not('.accordion-wrapper').hide(); $list.find("tr").eq(0).show(); $list.find(".accordion-wrapper").click(function () { $list.find('.accordion-wrapper').not(this).siblings().fadeOut(500); $(this).siblings().fadeToggle(500); $(this).addClass('active'); $list.find('.accordion-wrapper').not(this).removeClass('active'); if ($list.find('.accordion-wrapper').hasClass('active')) { $list.find('.accordion-wrapper').not(this).removeClass('active'); } else if ($(this).is('.active')) { $(this).siblings().fadeToggle(500); $('.active').removeClass('active'); } }); });

最满意答案

更改

$(this).addClass('active');

$(this).toggleClass('active');

演示

Change

$(this).addClass('active');

to

$(this).toggleClass('active');

Demo

更多推荐

本文发布于:2023-08-06 10:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1446696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:手风琴   accordion   Jquery   table   toggled

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!