Jquery 返回数组中每个项目的索引号,并在 Rel 属性无限轮播中设置该索引

发布于 2024-08-20 05:03:04 字数 591 浏览 4 评论 0原文

我正在尝试操纵 Jquery Infinite Carousel 根据当前显示的图像动态调整图像容器的大小。我需要获取包含当前图像的 Li 元素的索引,但问题是无限轮播会自动删除并重新排序 Li,这意味着它们的 EQ() 属性不断变化。

因此,我需要在页面加载时、幻灯片开始和无限轮播对 Li 重新排序之前,根据它们的索引位置为它们分配 REL 属性。

基本上,我的 Html 是这样的:

<li></li>
<li></li>
<li></li>

我需要使用 jquery 在页面加载时将其变成这样:

<li rel="1"></li>
<li rel="2"></li>
<li rel="3"></li>

我已经研究了很多关于 jQuery API 的内容,但我不知道要使用哪个属性或属性组合:

index(),
each(),
inArray(),
get()

谢谢感谢您的帮助!

I am trying manipulate Jquery Infinite Carousel into dynamically resizing the image container based on the currently displayed image. I need to get the index of the Li element that contains the current image, but the problem is that Infinite Carousel removes and reorders the Li's automatically, which means that their EQ() properties are constantly changing.

So, I need to assign them a REL attribute based on their index position when the page loads, before the slideshow begins and Infinite Carousel reorders the Li's.

Basically, my Html is like this:

<li></li>
<li></li>
<li></li>

and I need to use jquery to make it into this on page load:

<li rel="1"></li>
<li rel="2"></li>
<li rel="3"></li>

I've researched a bunch on the jQuery API but I can't figure out which property or combination of properties to use:

index(),
each(),
inArray(),
get()

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆凄美了谁 2024-08-27 05:03:04

试试这个:

$("ul").each(function() {
    $(this).children("li").each(function(i) {
        $(this).attr("rel", i+1);
    });
});

Try this:

$("ul").each(function() {
    $(this).children("li").each(function(i) {
        $(this).attr("rel", i+1);
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文