为什么我的html文档中的元素索引没有更新? (jQuery问题) [英] why my element index is not updating in my html document ? ( jquery issue )

查看:61
本文介绍了为什么我的html文档中的元素索引没有更新? (jQuery问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的网页:请检查

我在页面上放置了两个链接,单击第一个链接会提醒每个div中的文本及其元素位置(索引).单击第二个链接,将最后一个div的位置更改为第二个div的位置,反之亦然.现在第二个位置的最后一个div,但其索引不变.(再次单击第一个链接)第三个元素在第二个位置,其索引仍为3,不应该为2吗?还是在元素索引从一个位置移动到另一位置时如何更新?请帮助

I have placed two links in the page, clicking on the first link alerts the text in each div and its element position (index). clicking on the second link change the position of the last div to the position of the second div and vice versa. now the last div on the second position but its index doesn't change.(again click on the first link) The third element is in the second position and its index is still 3, it shouldn't be 2 ? or how can I update the element index as it moves from one position to another ? Please help

非常感谢

推荐答案

正如MvanGeest所说: 当您单击时,您会看到:

As MvanGeest commented: When you click you see this:

1 -> 1
2 -> 3
3 -> 2

但是浏览器是做什么的

1 -> 1
2 -> 2{top = top - 35}
3 -> 3{top = top + 35}

所以顺序仍然是1,2,3 ...好吧,编辑您想要做的就是在您的move函数中添加以下内容:

So the order is still 1,2,3 ... ok EDIT what you want to do is add something like this to your move function:

$('#main #3').insertAfter($('#main #1'));

这会将第3个元素移到第1个元素之后,以便浏览器像您一样看到它.

this will move the 3rd element after the 1st so the browser sees it like you do.

这篇关于为什么我的html文档中的元素索引没有更新? (jQuery问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆