jquery实现隔行变色

来源:互联网 发布:js数组中添加对象方法 编辑:程序博客网 时间:2024/04/28 05:18

 

Code:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  2. <html>  
  3.   <head>  
  4.     <title>ghcolor.html</title>  
  5.       
  6.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  7.     <meta http-equiv="description" content="this is my page">  
  8.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">  
  9.       
  10.     <script type="text/javascript" src="./js/jquery-1.4.4.js"></script>  
  11.     <script type="text/javascript">  
  12.         $(function(){  
  13.           
  14.             $("tr:even").addClass("even");//基数行  
  15.             $("tr:odd").addClass("odd");//偶数行   
  16.               
  17.             $("tr:even").hover(  
  18.                 function(){  
  19.                     clr = $(this).css("background-color");  
  20.                     $(this).css("background-color","red");  
  21.   
  22.                 },function(){  
  23.                      $(this).css("background-color",clr);  
  24.                  }  
  25.             );  
  26.             $("tr:odd").hover(  
  27.                 function(){  
  28.                     clr = $(this).css("background-color");  
  29.                     $(this).css("background-color","blue");  
  30.   
  31.                 },function(){  
  32.                      $(this).css("background-color",clr);  
  33.                  }  
  34.             );  
  35.         });  
  36.     </script>  
  37.     <style type="text/css">  
  38.         .even{  
  39.             background-color:gray;  
  40.         }  
  41.         .odd{  
  42.             background-color:green;  
  43.         }  
  44.     </style>  
  45.   </head>  
  46.     
  47.   <body>  
  48.     <table>  
  49.         <thead>  
  50.         <tr>  
  51.             <th>序号</th>  
  52.             <th>姓名</th>  
  53.             <th>昵称</th>  
  54.             <th>性别</th>  
  55.         </tr>  
  56.         </thead>  
  57.         <tbody>  
  58.             <tr>  
  59.                 <td>1</td>  
  60.                 <td>陈志明</td>  
  61.                 <td>GoodWell</td>  
  62.                 <td></td>  
  63.             </tr>  
  64.             <tr>  
  65.                 <td>2</td>  
  66.                 <td>陈志明</td>  
  67.                 <td>GoodWell</td>  
  68.                 <td></td>  
  69.             </tr>  
  70.             <tr>  
  71.                 <td>3</td>  
  72.                 <td>陈志明</td>  
  73.                 <td>GoodWell</td>  
  74.                 <td></td>  
  75.             </tr>  
  76.             <tr>  
  77.                 <td>4</td>  
  78.                 <td>陈志明</td>  
  79.                 <td>GoodWell</td>  
  80.                 <td></td>  
  81.             </tr>  
  82.         </tbody>  
  83.     </table>  
  84.   </body>  
  85. </html>  

 

原创粉丝点击