我对普通的jQuery有一个令人困惑的问题。无论何时单击标题详细信息,我都需要使第一个 div detailsPane始终保持打开状态。换句话说,无论单击哪个 div 的任何标题,div detailsPane 都应该始终保持打开状态。但我希望其余的能够像切换一样单击打开和关闭。
HTML 如下
<div class="petStockAccordion">
<div id="accordion">
<!-- DETAILS -->
<h2 class="current">
<a href="#tab-details" class="tab_01">
details
</a>
</h2>
<div class="pane detailsPane" style="display:block">
DIV 1
</div>
<!-- Ingredients -->
<h2>
<a href="#tab-reviews" class="tab_02">
ingredients
</a>
</h2>
<div class="pane">
This needs further work.
</div>
<!-- Delivery -->
<h2>
<a href="#tab-deliveryTab" class="tab_03">
delivery
</a>
</h2>
<div class="pane">
Div3
</div>
<!-- Reviews -->
<h2>
<a href="#tab-reviews" class="tab_04">
reviews
</a>
</h2>
<div class="pane">
DIV4
</div>
</div>
</div>
jquery部分在下面
<script type="text/javascript">
function initMenu() {
$('.petStockAccordion #accordion .pane').hide();
$('.petStockAccordion #accordion .detailsPane').show();
$('#accordion h2 a').click(
function() { $(this).parent('h2').next('div').slideToggle('fast');
}
);
}
$(document).ready(function() {initMenu();});
</script>