我有票务系统。消息被放置在一个 div 中,并且该 div 隐藏了子消息(该票的回复)
单击箭头 - 显示线程子项。再次单击它会隐藏线程子项,并且箭头会上下移动。
我想要它,如果当前线程是打开的,用户点击另一个箭头,打开的箭头应该恢复回来,反之亦然。
jQuery
$(document).ready(function(){
$('h1').click(function(){
if ($(this).next('.parent').hasClass('showMe')){
$('.parent').removeClass('showMe').hide();
$(this).find("#ticket_arrow").removeClass('up');
$(this).find("#ticket_arrow").addClass('down');
} else {
$('.parent').removeClass('showMe').hide();
$(this).find("#ticket_arrow").removeClass('down');
$(this).find("#ticket_arrow").addClass('up');
$(this).next('.parent').addClass('showMe').show();
}
});
});
/**
Hides all sub threads on Load
**/
$('.parent').hide();
HTML
<style type="text/css">
.ticket_thread_h1 span{cursor:pointer}
.down{background:url(http://www.gc-cdn.com/personalstylist/down.png) no-repeat;width:15px;height:10px;display:block}
.up{background:url(http://www.gc-cdn.com/personalstylist/up.png) no-repeat;width:15px;height:10px;display:block}
</style>
<h1 id="ticket_thread_1" class="ticket_thread_h1">Thread # 1 <span id="ticket_arrow" class="down"> </span></h1>
<div class="parent">
<div class="sub_thread"><p>Thread Messages #1 1</p></div>
<div class="sub_thread"><p>Thread Messages #1 2</p></div>
</div>
<h1 id="ticket_thread_2" class="ticket_thread_h1">Thread # 2 <span id="ticket_arrow" class="down"> </span></h1>
<div class="parent">
<div class="sub_thread"><p>Thread Messages #2 1</p></div>
<div class="sub_thread"><p>Thread Messages #2 2</p></div>
</div>