gpt4 book ai didi

javascript - jquery如何在切换时更改父div的类

转载 作者:行者123 更新时间:2023-11-28 16:30:40 25 4
gpt4 key购买 nike

当我滑动切换我拥有的简单 Accordion 时,我想更改链接元素的类和包裹整个 Accordion 的 .revealBox div,具体取决于 Accordion 是打开还是关闭

我的jquery是

$(document).ready(function() {
// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText = 'Hide Information';
var hideText = 'Show Information';
var is_visible = false;
$('.collapseLink').append('<span class="dottedBot">' + showText + '</span>');
$('.revealBoxContents').show();
$('a.collapseLink').click(function() {
// switch visibility
is_visible = !is_visible;
// change the link depending on whether the element is shown or hidden
$(this).html((!is_visible) ? showText : hideText);
// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next('.revealBoxContents').slideToggle('slow');
// return false so any link destination is not followed
return false;
});
// toggle the bottom link
$('.collapseLink').click(function() {
$(this).parents('.revealBoxContents').stop(true, true).slideToggle('slow');
$(".collapseLink").html((!is_visible) ? showText : hideText);
$(this).parent('.item').toggleClass('current');

});
});

我的网址是

http://satbulsara.com/NSJ-local/eqs1.htm

谢谢

周六

最佳答案

您想在元素上使用 addClass() 函数。

http://api.jquery.com/addClass/

您也可以使用toggleClass() 来做到这一点,如 jQuery 文档所示:

$('div.foo').toggleClass(function() {
if ($(this).parent().is('.bar')) {
return 'happy';
} else {
return 'sad';
}
});

http://api.jquery.com/toggleClass/

关于javascript - jquery如何在切换时更改父div的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6114060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com