为了账号安全,请及时绑定邮箱和手机立即绑定

jquery 实现鼠标移动到table每行,此行高亮变色

标签:
JQuery

/*---实现效果的 Jquery 方法---*/
$.change =function(){
        var tableid='table'; 
        var overcolor='#FCF9D8';
        var color2='#F8F8F8';
        var color1='#FFFFFF'; 
        var tablename=document.getElementById(tableid);
        var tr=tablename.getElementsByTagName("tr");
        for(var i=1 ;i<tr.length;i++){
        tr[i].onmouseover=function(){
        this.style.backgroundColor=overcolor;
    };
        tr[i].onmouseout=function(){
        if(this.rowIndex%2==0){
    this.style.backgroundColor=color2;
        }else{
    this.style.backgroundColor=color1;
   }
  };
        if(i%2==0){
        tr[i].className="color2";
  }else{
        tr[i].className="color1";
  }
 }
};


/*----效果页面及调用上面的jquery 方法---*/

$(document).ready(function() {
        //初始化页面时执行 
        $.change();
    });

  <table width="100%" border="0"
                        cellpadding="0" cellspacing="0" >
        <tr>
            <th >序号</th>
            <th >用户名称</th>
            <th >手机号码</th>
            <th >邮箱地址</th>
            <th >创建日期</th>

        </tr>
           
           <tr class="on">
            <td height="39" align="center">1</td>
            <td align="left"><a href="javascript:look('4','tclabc00001');">tclabc000sadfsadfsadfsafdsafdsafsad01</a></td>
                        <td align="left">13800138000</td>
            <td align="left">tclab23423dsasdfsafsadfasdfsac00001@email.com</td>
            <td align="left">2012-03-06</td>
          </tr>
    </table>

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
移动开发工程师
手记
粉丝
39
获赞与收藏
243

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消