1. Change colors on alternate lines
$("tr:odd" ).css("background-color","#eeeeee");
$("tr:even").css("background-color","#ffffff");
Or do it in one line:
$("table tr:nth -child(odd)").css("background-color","#eeeeee");
:nth-child matches the Nth child or odd-even element under its parent element
2. The mouse changes color
$("tr ").live({
mouseover:function(){
$(this).css("background-color","#eeeeee");
},
mouseout:function() {
$(this).css("background-color","#ffffff");
}
})
or
$("tr").bind("mouseover",function(){
$(this).css("background-color","#eeeeee");
})
$("tr").bind("mouseout",function(){
$(this ).css("background-color","#ffffff");
})
Of course, both live() and bind() can bind multiple events at the same time or separately.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn