我正在嘗試使用javascript/jquery。如何隱藏和顯示縮略圖上的圖像點擊使用jquery或javascript
我有下面的HTML,我想在圖像鏈接的「onclick」事件工作。
<div id="galleryContainer">
<ul class="galleryThumbnails">
<li><a href="/99/english/destinations_offers/destinations/asiapacific/india/newdelhi/photo.aspx?item=media_616165_ID0EV&menu=image_616165#mplayer_616165">
<img width="70" height="56" src="http://corp.com/99/english/images/thumb_616143_tcm481-616166.jpg"
class="mpMenuItemSelected" id="thumb_616165_ID0EV" title="New Delhi Zoo" alt="New Delhi Zoo"></a>
</li>
<li><a href="/99/english/destinations_offers/destinations/asiapacific/india/newdelhi/photo.aspx?item=media_616165_ID0E3&menu=image_616165#mplayer_616165">
<img width="70" height="56" src="http://corp.com/99/english/images/thumb_616146_tcm481-616168.jpg"
class="mpMenuItemOff" id="thumb_616165_ID0E3" title="New Delhi Zoo" alt="New Delhi Zoo"></a>
</li>
<li><a href="/99/english/destinations_offers/destinations/asiapacific/india/newdelhi/photo.aspx?item=media_616165_ID0EDB&menu=image_616165#mplayer_616165">
<img width="70" height="56" src="http://corp.com/99/english/images/redfort_tcm481-616158.jpg"
class="mpMenuItemOff" id="thumb_616165_ID0EDB" title="New Delhi RedFort" alt="New Delhi RedFort"></a>
</li>
</ul>
<div id="media_616165_ID0EV" class="galleryImage">
<img width="390" height="312" alt="New Delhi Zoo" title="New Delhi Zoo" src="http://corp.com/99/english/images/10894_tcm481-616143.jpg"></div>
<div style="display: none;" id="media_616165_ID0E3" class="galleryImage">
<img width="390" height="312" alt="New Delhi Zoo" title="New Delhi Zoo" src="http://corp.com/99/english/images/deer_tcm481-616146.jpg"></div>
<div style="display: none;" id="media_616165_ID0EDB" class="galleryImage">
<img width="390" height="312" alt="New Delhi RedFort" title="New Delhi RedFort" src="http://corp.com/99/english/images/redfort_tcm481-616157.jpg"></div>
</div>
在上面HTML,我有縮略圖(請參閱UL)例如
<img width="70" height="56" src="http://corp.com/99/english/images/thumb_616143_tcm481-616166.jpg"
class="mpMenuItemSelected" id="thumb_616165_ID0EV" title="New Delhi Zoo" alt="New Delhi Zoo">
每一個縮略圖,它會顯示在現在,我已經得到了獨立galleryImage DIV部分點擊縮略圖圖像。例如對於上面的縮略圖,有
<div id="media_616165_ID0EV" class="galleryImage">
<img width="390" height="312" alt="New Delhi Zoo" title="New Delhi Zoo" src="http://corp.com/99/english/images/10894_tcm481-616143.jpg"></div>
我想按照縮略圖點擊來隱藏和顯示圖像。
編輯:
我有標籤的功能鏈接第一時間時,頁面呈現以下@Rahul代碼工作完美,但航行的任何選項卡,再回來就停止工作的原因後,是在相同的選項卡上回來後,我以前的jQuery代碼添加和具有相同內容的額外div,在jquery下面感到困惑,因爲我的頁面現在將具有相同的代碼兩次。第一次頁面渲染時請參閱示例代碼。導航到其他標籤和回來同一標籤,現在html頁面上之後立即
<div class="tabs-container" id="tab-container">
top above html is rendered here
</div>
是如下,上述代碼保留在那裏在頁面樣式=「顯示:無;」一個額外的div被添加到播放選項卡功能:
<div class="tabs-container" id="tab-container" style="display: none;">
top above html is rendered here
</div>
<div id="divContenttab5" style="display: block;" class="dynDiv">
<div class="tabs-container" id="tab-container">
top above html is rendered here
</div>
</div>
現在下面的Jquery停止工作,因爲有兩個相同類型的HTMLS的。
請建議!
謝謝。
最好的問候, MKS
檢查是否沒有元素標識符的重複。 – rahul 2010-11-09 09:39:55
@Rahul我如何檢查元素ID的重複,因爲這是代碼的一部分。請建議切換圖像標記的類 – 2010-11-09 09:48:01
您可以在文檔中擁有多個具有相同標識的元素。這將是無效的 – rahul 2010-11-09 11:06:27