您的位置:首页 > Web前端 > JQuery

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

2014-12-08 17:26 561 查看
jQuerytable隔行换色鼠标经过变色

一、隔行换色

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

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

$("tr:odd").css("background-color","#eeeeee");
$("tr:even").css("background-color","#ffffff");
或者一行搞定:

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

$("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").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");

})

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


当然live()和bind()都可以同时绑定多个事件或分开。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: