我是靠谱客的博主 深情水壶,这篇文章主要介绍jQuery实现table隔行换色和鼠标经过变色的两种方法,现在分享给大家,希望可以做个参考。

一、隔行换色

复制代码 代码如下:

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

最后

以上就是深情水壶最近收集整理的关于jQuery实现table隔行换色和鼠标经过变色的两种方法的全部内容,更多相关jQuery实现table隔行换色和鼠标经过变色内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部