jQuery练习2-表格隔行变色
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <title>exe_1.html</title> 5 <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 6 <script type="text/javascript" src="../js/jquery-1.9.1.js"></script> 7 <style type="text/css"> 8 .jishu{ 9 background:#0000ff; 10 } 11 .ershu{ 12 background:#ffff00; 13 } 14 </style> 15 </head> 16 <body> 17 <!--表格隔行变色--> 18 <table border="1" align="center"> 19 <tr> 20 <th>用户名</th> 21 <th>密码</th> 22 </tr> 23 <tr> 24 <td>张三</td> 25 <td>123456</td> 26 </tr> 27 <tr> 28 <td>李四</td> 29 <td>654321</td> 30 </tr> 31 <tr> 32 <td>王五</td> 33 <td>162534</td> 34 </tr> 35 </table> 36 <script type="text/javascript"> 37 38 //取得大于2行 39 //alert($("tr:gt(0)").html()); 40 41 $("tr:eq(0)").css({background:"blue"}); 42 $("tr:gt(0):even").css("background","red"); 43 $("tr:gt(0):odd").css("background","yellow"); 44 45 </script> 46 </body> 47 </html>
by hacket