早上好。 我喝了一些咖啡来补偿这个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