2010-02-07 50 views
0
$('.mydiv ul li:nth-child(4)').addClass("nth"); 

至少有8个li在那里,但它只选择第4但不是第8?jQuery:nth-​​child只选择一个?

+0

它为什么会选择8,当你有4个存在? – 2010-02-07 16:50:58

+0

是不是表示选择EVERY 4th? – 3zzy 2010-02-07 16:51:52

+0

编号:http://api.jquery.com/nth-child-selector/ – womp 2010-02-07 16:53:24

回答

5
$('.mydiv ul li:nth-child(4n)').addClass("nth"); 

讲究4n

+0

AAAH!谢谢 :) – 3zzy 2010-02-07 16:58:26