【发布时间】:2011-05-26 08:23:03
【问题描述】:
如何测试一张图片是一组图片的第一张还是最后一张?
我正在尝试使用以下代码使上一个和下一个按钮动画化,具体取决于我是否位于一系列图像的末尾:
var $current = jQuery("img .active");
var $next = $current.next();
if ($next != jQuery("img:first-child")
{
// show next item and the previous button
// seems to work?
} else if ($next == jQuery("img:last-child")
{
// hide the next button since we're at the end
// doesn't seem to work??
}
【问题讨论】:
-
id选择器
#img在做什么?是否有 ID 为img的元素持有图像?还是应该只是简单的img?另外,您的意思是img.active,它是类active的img 元素? -
抱歉打错了,我刚刚更正了。
标签: jquery conditional