如何縮短此代碼?每個CSS選擇器增加+1。除非選擇了.mug(x),否則所有Bio的div都是隱藏的。如何縮短此javascript代碼?顯示隱藏多個div
感謝
<script type='text/javascript'>
$(document).ready(function() {
$(".mug1").click(function() {
$("#bios div").hide();
$(".bio1").show();
});
$(".mug2").click(function() {
$("#bios div").hide();
$(".bio2").show();
});
$(".mug3").click(function() {
$("#bios div").hide();
$(".bio3").show();
});
});
</script>
<h2>Meet the team</h2>
<div id="mugshots">
<img src="images/img-mugshot.jpg" alt="mug" class="mug1"/>
<img src="images/img-mugshot.jpg" alt="mug" class="mug2"/>
<img src="images/img-mugshot.jpg" alt="mug" class="mug3"/>
</div>
<div id="bios">
<div class="bio1"></div>
<div class="bio2"></div>
<div class="bio3"></div>
</div>
您基本上正在實現[jQuery UI Accordion](http://jqueryui.com/demos/accordion/) – jrummell