JQuery to achieve table interlacing color change and mouse over the two methods of color change
- 2020-03-30 03:21:13
- OfStack
One, alternate color
Or one line:
: NTH -child matches the NTH child or even element under its parent element
Two, the mouse changes color
or
Of course, both live() and bind() can bind multiple events simultaneously or separately.
$("tr:odd").css("background-color","#eeeeee");
$("tr:even").css("background-color","#ffffff");
Or one line:
$("table tr:nth-child(odd)").css("background-color","#eeeeee");
: NTH -child matches the NTH child or even element under its parent element
Two, 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 simultaneously or separately.