获取嵌套列表项的索引
我正在尝试获取嵌套列表的索引。
我举了一个例子。
当您单击列表项时,您会看到以下内容,
list item 0
list item 0
list item 1
list item 1
list item 2
我希望它执行以下操作:
list item 0
list item 1
list item 2
list item 3
list item 4
有人能给我指出正确的方向吗?我希望我已经解释得足够好了。
如果演示无法加载,则代码如下,当您此时单击列表项时,它只会附加 ID。
$('li').click( function() {
var liIndex = $(this).index();
$(this).children().append(liIndex);
});
I'm trying to get the index of a nested list.
I've put an example up.
At the moment when you click a list item you get this
list item 0
list item 0
list item 1
list item 1
list item 2
I want it to do this:
list item 0
list item 1
list item 2
list item 3
list item 4
Could someone point me in the right direction please? I hope I've explained this well enough.
Here's the code if the demo wont load, It just appends the ID when you click a list item at the moment.
$('li').click( function() {
var liIndex = $(this).index();
$(this).children().append(liIndex);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
http://jsfiddle.net/5zJD8/36/
您可以在此处查找更多信息: http://api.jquery.com/index/
Try this:
http://jsfiddle.net/5zJD8/36/
you may look for more info here : http://api.jquery.com/index/
这做同样的事情,但稍微省力一点:
This does the same thing, but a bit less effort: