【发布时间】:2019-02-19 03:40:22
【问题描述】:
我有一个与 toggle() 函数切换的 div 列表。当它切换时,用于切换 div 的按钮会将文本从“+”更改为“-”。但是当我点击下一个按钮 div 或上一个按钮 div 时,旧按钮没有用“-”更改文本(因为已关闭,所以它应该将文本更改为“-”。所以我想更改如果 div 已关闭,则按钮的文本为“-”。
$(".p1").hide();
$(".p1-venue").hide();
$(".p1-img").hide();
$(".btn1").click(function() {
if ($.trim($(this).text()) === '+') {
$(this).text('-');
} else {
$(this).text('+');
}
var $p1 = $(this).next(".p1").toggle();
var $p1venue = $(this).parents().next(".p1-venue").toggle();
var $p1img = $(this).parent().parent().parent().parent().find(".p1-img").toggle();
$(".p1").not($p1).hide();
$(".p1-venue").not($p1venue).hide();
$(".p1-img").not($p1img).hide();
});
【问题讨论】: