第一步:写html代码部分:
<table style="width:300px;">
<tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>3</td></tr> <tr><td>4</td></tr> <tr><td>5</td></tr> <tr><td>6</td></tr> <tr><td>7</td></tr> <tr><td>8</td></tr> <tr><td>9</td></tr> </table>第二步:插入jquery插件:
<script src="js/jquery-3.1.0.min.js"></script>
第三步:写jquery代码:
<script type="text/javascript">
$(document).ready(function(){ $("tr:nth-child(2n+1)").css("background","red"); $("tr:first-child").css("background","blue"); $("tr:last-child").css("background","green");});
</script>