获取索引 REVERSED 中的元素位置
我做了一些谷歌搜索,发现了一些相当复杂的解决方案,但是有没有一种简单的方法可以让 jQuery 反转元素索引。
目前
$('.elementClass').index(this);
将为我提供“elementClass”类中单击的元素的位置,但我需要将其反转!例如,我有 5 <跨度>一行中的元素,如果单击第四个,我希望返回为 1,而不是 3(第一个返回为 0)
I've done some Googling and found some pretty complex solutions, but is there a simple way of getting jQuery to reverse an element index.
Currently
$('.elementClass').index(this);
Will give me the position of the clicked element within the class "elementClass" but I need this reversed! For example, I have 5 < span > elements in a row, if the 4th one is clicked, I want the return to be 1, not 3 (the first one being returned as 0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需使用
elementClass
类存储整个元素列表,然后从总数中减去索引即可。此处的工作示例已更新,以便第四个元素警报“1”: http://jsfiddle.net/vM3Bb/1 /
Just store your entire list of elements with the class of
elementClass
, and subtract the index from the total number.Working example here, updated so that the 4th element alerts "1": http://jsfiddle.net/vM3Bb/1/
这对我有用:
This works for me: