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

时间:2014-06-15 10:15:32   收藏:0   阅读:329

一、隔行换色

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

如果table表格是动态添加的 请参阅:http://blog.csdn.net/itmyhome1990/article/details/30245973



jQuery实现table隔行换色和鼠标经过变色,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!