得到每个< li>使用jQuery的索引号 [英] Get each <li> index number with jQuery
本文介绍了得到每个< li>使用jQuery的索引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取少数< li>
的索引号。李是8,我正试图得到每个李的号码。
I'm trying to get the index number of few <li>
's. The li's are 8 and I'm trying to get each li's number.
每次点击我都做这个功能:
On each li click I do this function:
var str = $('#amastorage li').index();
alert(str);
总是给我8美元。
编辑:
我就是这样:
$("#amastorage ul").find('a').click(function () {
var str = $('#amastorage li').index();
alert(str);
});
我无法改变: $(#amastorage ul)。find( 'a')。点击(function(){
因为它来自一个插件而且不起作用。
I cant change: $("#amastorage ul").find('a').click(function () {
because It's from a plugin and it won't work.
谢谢
如何提醒我选择的李号码?
How can I alert the li number I choosed?
推荐答案
你需要使用点击功能中的此
对象。
You need to use the this
object in the click function.
$("li").click(function(){
var str = $(this).index();
alert(str);
});
每次修改:
$("#amastorage ul").find('a').click(function () {
var str = $(this).parents("li").index();
alert(str);
});
这篇关于得到每个< li>使用jQuery的索引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文