如何获取ul标签中特定li的位置? [英] How to get the position of an specific li in a ul tag?
本文介绍了如何获取ul标签中特定li的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得一个用jQuery
悬停的数字li
.
这是我的代码:
I want to get number of one li
that I hover on with jQuery
.
this is my code :
<ul>
<li></li>
<li></li>
<li></li> /* I want hover on this element */
<li></li>
<li></li>
</ul>
我想要在顶部代码中的某个元素上悬停时获取所有lies
...的编号.例如,在顶部代码中,我想要3(这意味着该第三个元素)
I want when hover on certain element in top code get number of all lies
.... for example in top code I want get 3 (This means that this third element)
推荐答案
您可以使用此
var number = $(this).index() + 1;
演示此处
Demo here
.index() 从0开始,所以我添加了+1,因为您想从1开始计数.
The .index() starts at 0 so I added +1 because you wanted to start counting from 1.
这篇关于如何获取ul标签中特定li的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文