热门关键字:
jquery > jquery教程 > jquery教程 > jQuery实现table隔行换色和鼠标经过变色

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

363
作者:管理员
发布时间:2021/2/7 15:45:12
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3951
一、隔行换色


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




如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:HTML
友荐云推荐