【发布时间】:2016-11-11 12:53:45
【问题描述】:
我有多个显示/隐藏 div,文本从 Expand 更改为 Reduce。如果有多个下拉菜单,则文本不会更改。有我的JSFiddle,你可以测试一下,删掉一段。有什么解决方案吗? :)
这是我的 JQuery
$(".section .section-title").click(function(){
$(this).closest(".section").find('.dropdown-content').slideToggle(100);
$(this).find('.expand').toggleClass('expanded');
if ($.trim($(".expand").text()) === 'Expand') {
$(".expand").text('Reduce');
} else {
$(".expand").text('Expand');
}
});
【问题讨论】:
-
哪个下拉菜单?你想要额外的 div 吗?
-
你的 if 条件不起作用,使用 if($.trim($(this).find('.expand').text()) === 'Expand'){ $(this ).find(".expand").text('Reduce'); } else { $(this).find(".expand").text('Expand'); }
标签: javascript jquery html css events