获取具有索引号的特定同级
我正在制作横幅幻灯片,但在使用导航时遇到了麻烦:
function slideSwitch(item) {
if(item) {
//Problem
var $active = $('#banner div').index(item);
var $activeImage = $('#banner img').index(item);
} else {
var $active = $('#banner div.active');
var $activeImage = $("img[src$='/images/active.png']");
if ($active.length == 0) $active = $('#banner div:last');
if ($activeImage.length == 0) $activeImage = $('#banner img:last');
}
}
$("#banner img").click(function () {
slideSwitch($(this));
});
问题出在单击 #banner 中的 img 时。我想要传输图像(navigation.indicator)的位置,从而能够淡入所选横幅。问题就在这里:
var $active = $('#banner div').index(item);
var $activeImage = $('#banner img').index(item);
我没有使用index(),因为我没有选择对象。如何做到这一点?
我也尝试过“$('#banner div')[item]”,但这仍然不返回对象。
Im working on a banner-slideshow, but working with the navigation i've run into trouble:
function slideSwitch(item) {
if(item) {
//Problem
var $active = $('#banner div').index(item);
var $activeImage = $('#banner img').index(item);
} else {
var $active = $('#banner div.active');
var $activeImage = $("img[src$='/images/active.png']");
if ($active.length == 0) $active = $('#banner div:last');
if ($activeImage.length == 0) $activeImage = $('#banner img:last');
}
}
$("#banner img").click(function () {
slideSwitch($(this));
});
The problem is when clicking on an img in #banner. I want to get the position of the image (navigation.indicator) transfered and thereby be able to fade in the selected banner. The problem is here:
var $active = $('#banner div').index(item);
var $activeImage = $('#banner img').index(item);
Im not using index() right since I dont get an object selected.. how to do this?
I've also tried with "$('#banner div')[item]" but this still doesnt return an object..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 jQuery 对象上使用 [] 返回列表中该位置的基础 HTML 节点。您想要的是在 jQuery 中重新包装该节点。
尝试
"$($('#banner div')[item])"
Using [] on a jQuery object returns the underlying HTML node for that position in the list. What you want is to re-wrap that node in jQuery.
Try
"$($('#banner div')[item])"