:nth-child(Xn+Y)
匹配集合中子集每隔X个元素的第Xn+Y元素集合。返回匹配元素集合
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("ul li:nth-child(3n+1)").append("<span> - 3n + 1!</span>");
});
</script>
<style>
div { float:left; }
span { color:blue; }
</style>
</head>
<body>
<div><ul>
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
<li>Glen</li>
<li>Tane</li>
<li>Ralph</li>
<li>David</li>
</ul></div>
<div><ul>
<li>Sam</li>
</ul></div>
</body>
</html>
$("ul li:nth-child(3n+1)").append("<span> - 3n + 1!</span>");
匹配ul中包li的li元素集合,且仅仅为li子集中第3n+1个li元素的li元素集合。以下为匹配元素集合
<li>John</li>
<li>Glen</li>
<li>David</li>
<li>Sam</li>