gpt4 book ai didi

jquery - 有类在 if 条件下不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 12:48:20 25 4
gpt4 key购买 nike

我为 Accordion 编写了以下代码,但是当我对其进行测试时,'not' 显示了两次,而 'hve' 根本没有显示。

$('.st-accordion li a').click(function() {

if ($(this).parent().not('activeaccordion')) {
$(this).parent().addClass('activeaccordion')
alert('not');
$(this).next().slideToggle();
} else {
if ($(this).parent().hasClass('activeaccordion')) {
alert('hve');
$(this).parent().removeClass('activeaccordion')
$(this).next().slideToggle();
}
}
});

最佳答案

使用

if(!$(this).parent().hasClass('activeaccordion')){

您还可以使用 $(this).parent().toggleClass('activeaccordion'); 设置类(如果未设置),反之亦然。

关于jquery - 有类在 if 条件下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26329208/

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