jQuery实现table隔行换色和鼠标经过变色的两种方法_Javascript教程-查字典教程网
jQuery实现table隔行换色和鼠标经过变色的两种方法
jQuery实现table隔行换色和鼠标经过变色的两种方法
发布时间:2016-12-30 来源:查字典编辑
摘要:一、隔行换色复制代码代码如下:$("tr:odd").css("background-color","#eeeeee");$("tr:eve...

一、隔行换色

复制代码 代码如下:

$("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()都可以同时绑定多个事件或分开。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类