我想根据他们的订单为ul儿童制作不同的背景颜色,我如何使用jquery获得儿童的顺序.
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
<li>f</li>
</ul>
$('ul li').bind('mouseover', function(e){
//how can I get the order of the childre
//when hover on c it shoul returns 3
alert("child order ");
});
Run Code Online (Sandbox Code Playgroud)
这是一个例子 http://jsfiddle.net/sHefJ/
对于该HTML子集,使用...
$(this).index() + 1
Run Code Online (Sandbox Code Playgroud)
......就足够了.
我添加了,1因为您的示例中的编号系统似乎不是0基于.