只能改變?cè)械男械念伾?/h1>
只能改變?cè)械膖r行的顏色,新加的行顏色不變,請(qǐng)問大家這是什么原因?
? ? ? window.onload = function(){? ? ? ? ? ? ? ? ?
? ? ?// 鼠標(biāo)移動(dòng)改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。
? ? ? ?var mycol=document.getElementsByTagName("tr");
? ? ? ?for (var i=0; i<mycol.length; i++){
? ? ? ? ? mychange(mycol[i]);
? ? ? ?}??
}
? ? ?function mychange(tr){
? ? ? tr.onmouseenter=function(){
? ? ? ? tr.style.backgroundColor="#f2f2f2";
? ? ? };
? ? ? tr.onmouseout=function(){
? ? ? ? tr.style.backgroundColor="#fff";
? ? ? };
? ? ?}
? ? ?
只能改變?cè)械膖r行的顏色,新加的行顏色不變,請(qǐng)問大家這是什么原因?
? ? ? window.onload = function(){? ? ? ? ? ? ? ? ?
? ? ?// 鼠標(biāo)移動(dòng)改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。
? ? ? ?var mycol=document.getElementsByTagName("tr");
? ? ? ?for (var i=0; i<mycol.length; i++){
? ? ? ? ? mychange(mycol[i]);
? ? ? ?}??
}
? ? ?function mychange(tr){
? ? ? tr.onmouseenter=function(){
? ? ? ? tr.style.backgroundColor="#f2f2f2";
? ? ? };
? ? ? tr.onmouseout=function(){
? ? ? ? tr.style.backgroundColor="#fff";
? ? ? };
? ? ?}
? ? ?
2018-02-12
window.onload表示在網(wǎng)頁加載完成之后執(zhí)行函數(shù)。所以這個(gè)函數(shù)只會(huì)在加載之后只會(huì)執(zhí)行一次
需要再在添加函數(shù)中加入該函數(shù)