手风琴选择的数据无法正常工作

时间:2014-11-30 11:33:06

标签: jquery html css css3 accordion

Accordian工作大多很好,但选择的背景颜色显示不正确。

请帮忙,如何解决。

	jQuery('.accordion dt').click(function() {
	     jQuery(this).toggleClass('close').closest('dt').next()
	     .slideToggle().siblings('.accordion_content').slideUp();
	});
	jQuery('.accordion_content').hide();
.accordion dt {border-bottom: 1px solid #fff;display: block;cursor: pointer;padding: 8px 12px;color: #404549;font-size:19px;}
.accordion dt .accordion_icon {float: right;}
.accordion dt{background: url(../images/open.png) no-repeat 98% center #e3eaf0;}
.accordion dt:nth-child(4n+1){background-color: #d7e0e7;}
.accordion dt.close{background: url(../images/close.png) #005baa no-repeat 98% center;color:#fff;}
.accordion_content {margin: 0;padding: 15px;}
.accordion dd p{font-size: 14px;line-height: 18px;margin-bottom: 10px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<dl class="accordion">
			    
			    <dt>Step 6<i class="open"></i></dt>
			    <dd class="accordion_content">
			    	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. </p>
			    </dd>

			    <dt>Step 7<i class="open"></i></dt>
			    <dd class="accordion_content">
			    	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. </p>
			    </dd>


			    <dt>Step 8<i class="open"></i></dt>
			    <dd class="accordion_content">
			    	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. </p>
			    </dd>

			    <dt>Step 9<i class="open"></i></dt>
			    <dd class="accordion_content">
			    	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. </p>
			    </dd>

			    <dt>Step 10<i class="open"></i></dt>
			    <dd class="accordion_content">
			    	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. </p>
			    </dd>
			</dl>

1 个答案:

答案 0 :(得分:0)

您必须从.close删除.siblings()课程。

&#13;
&#13;
jQuery('.accordion_content').hide();
jQuery('.accordion dt').first().toggleClass('close').next().slideToggle();

jQuery('.accordion dt').click(function() {
  jQuery(this).toggleClass('close').next().slideToggle().siblings('.accordion_content').slideUp();
  jQuery(this).siblings().removeClass('close');
});
&#13;
.accordion dt {
  border-bottom: 1px solid #fff;
  display: block;
  cursor: pointer;
  padding: 8px 12px;
  color: #404549;
  font-size: 19px;
}
.accordion dt .accordion_icon {
  float: right;
}
.accordion dt {
  background: url(../images/open.png) no-repeat 98% center #e3eaf0;
}
.accordion dt:nth-child(4n+1) {
  background-color: #d7e0e7;
}
.accordion dt.close {
  background: url(../images/close.png) #005baa no-repeat 98% center;
  color: #fff;
}
.accordion_content {
  margin: 0;
  padding: 15px;
}
.accordion dd p {
  font-size: 14px;
  line-height: 18px;
  margin-bottom: 10px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<dl class="accordion">

  <dt>Step 6<i class="open"></i></dt>
  <dd class="accordion_content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit.</p>
  </dd>

  <dt>Step 7<i class="open"></i></dt>
  <dd class="accordion_content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit.</p>
  </dd>


  <dt>Step 8<i class="open"></i></dt>
  <dd class="accordion_content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit.</p>
  </dd>

  <dt>Step 9<i class="open"></i></dt>
  <dd class="accordion_content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit.</p>
  </dd>

  <dt>Step 10<i class="open"></i></dt>
  <dd class="accordion_content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit.</p>
  </dd>
</dl>
&#13;
&#13;
&#13;