返回jQuery实......登陆

jQuery实现table隔行换色和鼠标经过变色

阿神2016-11-08 11:14:38341

一、隔行换色

$("tr:odd").css("background-color","#eeeeee"); 
$("tr:even").css("background-color","#ffffff");

或者一行搞定:

$("table tr:nth-child(odd)").css("background-color","#eeeeee");

:nth-child 匹配其父元素下的第N个子或奇偶元素

二、鼠标经过变色 

$("tr").live({ 
    mouseover:function(){ 
        $(this).css("background-color","#eeeeee"); 
    }, 
    mouseout:function(){ 
        $(this).css("background-color","#ffffff"); 
    } 
})

或者  

$("tr").bind("mouseover",function(){ 
    $(this).css("background-color","#eeeeee"); 
}) 
$("tr").bind("mouseout",function(){ 
    $(this).css("background-color","#ffffff"); 
})

当然live()和bind()都可以同时绑定多个事件或分开。


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送