jQuery實(shí)現(xiàn)table隔行換色和鼠標(biāo)經(jīng)過變色的兩種方法_jquery
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 21:24:32
jQuery實(shí)現(xiàn)table隔行換色和鼠標(biāo)經(jīng)過變色的兩種方法_jquery
jQuery實(shí)現(xiàn)table隔行換色和鼠標(biāo)經(jīng)過變色的兩種方法_jquery:一、隔行換色 代碼如下: $(tr:odd).css(background-color,#eeeeee); $(tr:even).css(background-color,#ffffff); 或者一行搞定: 代碼如下: $(table tr:nth-child(odd)).css(background-c
導(dǎo)讀jQuery實(shí)現(xiàn)table隔行換色和鼠標(biāo)經(jīng)過變色的兩種方法_jquery:一、隔行換色 代碼如下: $(tr:odd).css(background-color,#eeeeee); $(tr:even).css(background-color,#ffffff); 或者一行搞定: 代碼如下: $(table tr:nth-child(odd)).css(background-c

一、隔行換色
代碼如下:
$("tr:odd").css("background-color","#eeeeee");
$("tr:even").css("background-color","#ffffff");
或者一行搞定:
代碼如下:
$("table tr:nth-child(odd)").css("background-color","#eeeeee");
:nth-child 匹配其父元素下的第N個子或奇偶元素
二、鼠標(biāo)經(jīng)過變色
代碼如下:
$("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");
})
當(dāng)然live()和bind()都可以同時(shí)綁定多個事件或分開。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
jQuery實(shí)現(xiàn)table隔行換色和鼠標(biāo)經(jīng)過變色的兩種方法_jquery
jQuery實(shí)現(xiàn)table隔行換色和鼠標(biāo)經(jīng)過變色的兩種方法_jquery:一、隔行換色 代碼如下: $(tr:odd).css(background-color,#eeeeee); $(tr:even).css(background-color,#ffffff); 或者一行搞定: 代碼如下: $(table tr:nth-child(odd)).css(background-c