我有兩個列表 - 第一個列表中有一個名稱,大圖和說明,第二個列表是小縮略圖。當點擊縮略圖時,我需要相應的li,只有較大的圖像和文字纔會顯示。因此,如果單擊John Doe的縮略圖,我需要顯示較大的John Doe圖像和文本,並確保較大的Bob Doe和Tom Doe圖像和文本被隱藏。我還想在加載頁面時顯示第一個較大的圖像和說明。這是我的HTML和jQuery到目前爲止 - 謝謝!當點擊不同的li時jQuery顯示li
<div id="bios">
<ul>
<li>
<img src="../img/jd.jpg" alt="John Doe">
<br>
<span class = "name">John Doe</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate diam ut porta pharetra. Nunc egestas ac turpis nec tempor.</p>
</li>
<li>
<img src="../img/bd.png" alt="Bob Doe">
<br>
<span class = "name">Bob Doe</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate diam ut porta pharetra. Nunc egestas ac turpis nec tempor.</p>
</li>
<li>
<img src= "../img/td.png" alt="Tom Doe">
<br>
<span class = "name">Tom Doe</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate diam ut porta pharetra. Nunc egestas ac turpis nec tempor.</p>
</li>
</ul>
</div>
<div id = "thumb">
<ul>
<li>
<img src="../img/jdthumb.png" alt="John Doe">
<br>
John Doe
</li>
<li>
<img src="../img/bdthumb.png" alt="Bob Doe">
<br>
Bob Doe
</li>
<li>
<img src= "../img/tdthumb.png" alt="Tom Doe">
<br>
Tom Doe
</li>
</ul>
</div>
的jQuery:
$("#bios li").first().css("display", "block");
$("#thumb li").on('click', function() {
$("#bios li").css("display", "block");
$(this).siblings('li').slideToggle();
});
真棒 - 偉大工程,謝謝! – epg388