jQuery查找元素的位置 [英] jquery find element's position

查看:83
本文介绍了jQuery查找元素的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<ul>
   <li>one</li>
   <li>element</li>
   <li>text</li>
   <li>val</li>
</ul>

我如何在点击的liul中获得位置?

how can i get the position in the ul of the clicked li ?

推荐答案

我认为这将为您做到:

$("li").click(function () {

   alert($(this).index());

});

请注意,index()函数返回jquery集合中项目的索引.如果页面上有多个列表,请确保选择器仅选择所需的列表项.

Note that the index() function returns the index of the item in the jquery collection. If you have multiple lists on the page, make sure your selector only selects the list items that you want.

这篇关于jQuery查找元素的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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