jQuery next()用于画廊 [英] Jquery next() for a gallery
问题描述
我自己创建了一个灯箱画廊,但是在加载下一张和上一张图片时遇到问题
$("a.lightbox").click(function (e) {
var a = $(this).next().attr('href');
alert(a);
});
如您所见,这是行不通的,我需要下一个元素的href包含.我的HTML是这样的:
I'm creating a kind of lightbox gallery by myself but I have problem with loading next and previous images
$("a.lightbox").click(function (e) {
var a = $(this).next().attr('href');
alert(a);
});
As you see this thing doesn't work and I need the href contain of the next element.My HTML is something like this:
<ul class="listing">
<li><a href="imgs/eli.jpg" id="1" class="lightbox"><img src="thumbs/eli_t.jpg" width="150" height="100" class="images" /></a></li>
<li><a href="imgs/ggallin.jpg" id="2" class="lightbox"><img src="thumbs/ggallin_t.jpg" width="150" height="100" class="images" /></a></li>
<li><a href="imgs/jontarata.jpg" id="3" class="lightbox"><img src="thumbs/jontarata_t.jpg" width="150" height="100" class="images" /></a></li>
<li><a href="imgs/macka s tatuirovki.jpg" id="4" class="lightbox"><img src="thumbs/macka s tatuirovki_t.jpg" width="150" height="100" class="images" /></a></li>
<li><a href="imgs/mk7.jpg" id="5" class="lightbox"><img src="thumbs/mk7_t.jpg" width="150" height="100" class="images" /></a></li>
<li><a href="imgs/P5010345.jpg" id="6" class="lightbox"><img src="thumbs/P5010345_t.jpg" width="150" height="100" class="images" /></a></li>
</ul>
推荐答案
您正在a
元素上调用next
. a
标记之后没有元素.您可以首先获取父级,获取下一个li
,然后从其子级中获取a
.
You are calling next
on your a
element. There are no elements that are after your a
tag. You could first get the parent, get the next li
and then grab the a
from its children.
var a = $(this).parent().next().children('a').attr('href');
这篇关于jQuery next()用于画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!