gpt4 book ai didi

javascript - 使用 jQuery 单击时切换 .html 文本

转载 作者:行者123 更新时间:2023-12-02 19:05:42 26 4
gpt4 key购买 nike

我正在尝试在我的网站上构建折叠展开功能。

我有以下内容,仅在尝试将“展开”文本更改为折叠时切换隐藏的 div,然后如果再次单击,则折叠>展开。

任何人都可以看到我做错了什么吗?

$('.coverage .expand').click(function(){
$(this).parent().parent().find('.subitems').toggle('slow', function() {
var togtit = $(this).parent().find('.expand');
if((togtit).is('Expand')){
togtit.html('Collapse')
} else {
togtit.html('Expand')
}
});
});

最佳答案

问题是您使用 .is()方法错误。您可以尝试以下方法:

$(this).parent().find(".expand").html(function(i, html) {
return html === "Expand" ? "Collapse" : "Expand";
});

关于javascript - 使用 jQuery 单击时切换 .html 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14336458/

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