用js 实现光棒效果和隔行换色

<script type="text/javascript">  

 

        $(function () {

     //获取所有的tr

      var str = $(document.getElementsByTagName("tr"));

            for (var i = 1; i < str.length; i++) {

                  str[i].onmouseover = function over() {       

                 this.style.background = "#87D3D8";             

    }              

   str[i].onmouseout = function out() {

                    this.style.background = "";          

    }

 }         

   for (i = 1; i < str.length; i++) {   

              (i % 2 == 0) ? (str[i].className = "color_td1") : (str[i].className = "color_td2");    

         }        

})      

 </script> <style type="text/css">   

  .color_td1   { BACKGROUND-COLOR:   red;   TEXT-ALIGN:   center  } 

.color_td2   {BACKGROUND-COLOR:Blue;   TEXT-ALIGN:   center  }

</style>

posted @ 2013-02-22 20:37  吕小龙  阅读(86)  评论(0)    收藏  举报