首页javascriptchildren_indexjQuery Selector - 如何选择偶数列表项

jQuery Selector - 如何选择偶数列表项

我们想知道如何选择偶数列表项。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
.e {
  color: red;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('ul li:nth-child(even)').addClass('e');
});
</script>
</head>
<body>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>    
    <li>5</li>    
    <li>6</li>    
  </ul>
</body>
</html>