【发布时间】:2022-02-05 13:03:35
【问题描述】:
我的 Html 看起来像
<h3><a href="#" title="story title">Story Title</a>
<img class="expandstory" src="/images/plus.png" /></h3>
<div class="description">Short description about the story</div>
<h3><a href="#" title="story title">Story Title</a>
<img class="expandstory" src="/images/plus.png" /></h3>
<div class="description">Short description about the story</div>
我的 jquery 看起来像
$('.description').hide();
$('.description:first').show();
$('.expandstory:first').attr('src','/images/minus.png');
$('.expandstory:first').addClass('collapsestory');
$(".expandstory").click(function() {
if($(this).attr('class')=='expandstory') {
$(".description").slideUp(500);
$(this).parent().nextAll('.description:first').slideToggle(500);
$(this).attr('src','/images/minus.png');
$(this).addClass('collapsestory');
$(this).removeClass('expandstory');
}
else {
$(".description").slideUp(500);
$(this).attr('src','/images/plus.png');
$(this).addClass('expandstory');
$(this).removeClass('collapsestory');
}
});
我正在让一个简单的事情变得更复杂,而且当我多次展开/折叠 div 时,这不起作用。
我无法更改 HTML 文件。请在 jquery 中为我提供好的解决方案。提前致谢。
【问题讨论】:
-
创建一个jsFiddle。另外,定义'不工作'
-
它的 jsFiddle.net 我猜.. :/
-
哎呀..我着急了。
标签: javascript jquery html