用jquery+css控制表格样式

表格效果如下:点滑过时变色

 

用jquery+css控制表格样式_第1张图片

 

代码:

 

  1. "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. "http://www.w3.org/1999/xhtml" >
  3.     无标题页
  4.     "../Js/jquery.js" type="text/javascript">
  5.     "text/javascript">
  6.         $(function(){
  7.           Test("#e0e0e0","Teal","#ffffff","#ffffff");
  8.         });
  9.         
  10.         function Test(evenBg,oddBg,evenBgNew,oddBgNew)
  11.         {
  12.            var trs=$("#mainTable tr");
  13.            var oddTr=$("#mainTable tr:odd");
  14.            var evenTr=$("#mainTable tr:even");
  15.            
  16.            evenTr.css("background-color",evenBg);
  17.            oddTr.css("background-color",oddBg);
  18.            alert(oddTr.eq(0).html());
  19.           // var oLength=oddTr.length
  20.            for(var i=0;i
  21.            {
  22.               oddTr.eq(i).bind("mouseover",function(){            
  23.                  $(this).css("background-color",oddBgNew);
  24.                  $(this).css("cursor","pointer");
  25.               });
  26.               
  27.               oddTr.eq(i).bind("mouseout",function(){               
  28.                $(this).css("background-color",oddBg);
  29.               });
  30.               
  31.               evenTr.eq(i).bind("mouseout",function(){
  32.                 $(this).css("background-color",evenBg);
  33.               });
  34.               
  35.               evenTr.eq(i).bind("mouseover",function(){
  36.                 $(this).css("background-color",evenBgNew);
  37.                  $(this).css("cursor","pointer");
  38.               });
  39.            }
  40.           
  41.            
  42. //           if(oddTr.length>evenTr.length)
  43. //           {
  44. //               oddTr[oddTr.length-1].bind("onmouseover",function(){
  45. //                oddTr[i].css("background-color",oddBgNew);
  46. //              }); 
  47. //           }
  48. //           else
  49. //           {
  50. //             evenTr[evenTr.length-1].bind("onmouseover",function(){
  51. //                evenTr[i].css("background-color",evenBgNew);
  52. //              });
  53. //           }
  54.            
  55.         }
  56.     
  57.     "text/css">
  58.         *
  59.         {
  60.             margin:0px;
  61.             padding:0px;
  62.             font-size:12px;
  63.             text-align:center;  
  64.             color:Yellow;
  65.             
  66.         }
  67.         #mainTable
  68.         {
  69.             width:500px;
  70.             border:5px solid #e0e0e0;
  71.             margin-top:40px;
  72.         }
  73.         
  74.         #mainTable tr
  75.         {
  76.             height:25px;
  77.             border:1px solid #e0e0e0;   
  78.           
  79.         }
  80.     
  81.     
  82.     class="style1" id="mainTable" >
  83.         这里是表格内容这里是表格内容
  84.         这里是表格内容这里是表格内容
  85.         这里是表格内容这里是表格内容
  86.         这里是表格内容这里是表格内容
  87.         这里是表格内容这里是表格内容
  88.         这里是表格内容这里是表格内容
  89.         这里是表格内容这里是表格内容
  90.         这里是表格内容这里是表格内容
  91.         这里是表格内容这里是表格内容
  92.         这里是表格内容这里是表格内容
  93.         这里是表格内容这里是表格内容
  94.         这里是表格内容这里是表格内容
  95.         这里是表格内容这里是表格内容
  96.     
  97.     

你可能感兴趣的:(jquery实例应用)