早上好。 我喝了一些咖啡來補償這個Javascript/jQuery問題帶來的壓力。JQuery - 確定其子女的父索引
基本上它這個問題的相反的事:Determining child index in it's parent
實際HTML(DOM)
<body>
<div id="content">
<div class="contentbox">
<div class="content">
<h2>Image Gallery Header</h2>
<div class="imageGallery">
<div class="image">
<a href="javascript:void(0);" class="prevImg"><i class="sx028"></i></a>
<ul>
<li id="g2i1">
<img src="imgs/imageGallery1.jpg" alt="" width="505" height="298" />
<p>Image Caption...</p>
</li>
<li id="g2i2">
<img src="imgs/imageGallery2.jpg" alt="" width="505" height="298" />
<p>Image Caption...</p>
</li>
</ul>
<a href="javascript:void(0);" class="nextImg" title="nächstes Bild"><i class="sx029"></i></a>
</div>
<div class="thumbs">
<a href="javascript:void(0);" class="prevImg"> </a>
<ul>
<li>
<img src="imgs/imageGallery1.jpg" alt="" width="149" height="88" />
</li>
<li>
<img src="imgs/imageGallery2.jpg" alt="" width="149" height="88" />
</li>
</ul>
<a href="javascript:void(0);" class="nextImg"> </a>
</div>
</div>
<h2>Image Gallery Caption</h2>
<p>
Some text.
</p>
</div>
<div class="content">
<h2>Image Gallery Header</h2>
<div class="imageGallery">
<div class="image">
<a href="javascript:void(0);" class="prevImg"><i class="sx028"></i></a>
<ul>
<li id="g2i1">
<img src="imgs/imageGallery4.jpg" alt="" width="505" height="298" />
<p>Image Caption...</p>
</li>
<li id="g2i2">
<img src="imgs/imageGallery5.jpg" alt="" width="505" height="298" />
<p>Image Caption...</p>
</li>
</ul>
<a href="javascript:void(0);" class="nextImg"><i class="sx029"></i></a>
</div>
<div class="thumbs">
<a href="javascript:void(0);" class="prevImg"> </a>
<ul>
<li>
<img src="imgs/imageGallery4.jpg" alt="" width="149" height="88" />
</li>
<li>
<img src="imgs/imageGallery5.jpg" alt="" width="149" height="88" />
</li>
</ul>
<a href="javascript:void(0);" class="nextImg"> </a>
</div>
</div>
<h2>Image Gallery Caption</h2>
<p>
Some text.
</p>
</div>
</div>
</div>
</body>
感謝您閱讀這一大堆。
僞JQuery的
$(".nextImg").click(function() {
var activeGallery = $(this).parents(".imageGallery").index();
alert("You've clicked the next image button of image Gallery #" + activeGallery);
});
結果(警報消息)
你點擊的圖片庫#1 <下一個圖像按鈕 - 如果你點擊了」。索引();「.imageGallery」的「nextImg」按鈕; 1
你點擊的圖像畫廊#2 <下一個圖像按鈕 - 如果你點擊了「.imageGallery」與索引()的「.nextImg」按鈕; 2
問:
怎樣 「爬」 上的類= 「NEXTIMAGE」家長元素DIV CLASS = 「imageGallery」和響應div的指數班級「imageGallery」?
它對我的畫廊項目的最後一步非常重要。謝謝你的迴應!
我已經做到了這一點,但我現在沒有任何代碼。嘗試使用根節點中的.next()方法。我會嘗試並在稍後發佈答案..還有其他你需要的東西 – ppumkin 2011-04-27 07:17:19