為什么這么寫提交上去表格直接就是紅色?
? ? window.onload = function(){
? ? ? ? trlist=document.getElementsByTagName("tr");
? ? ? ? for(var i=0;i<trlist.length;i++){
? ? ? ? ?trlist[i].onmouseover=bgcChange(trlist[i]);
? ? ? ? ?trlist[i].onmouseout=function(){this.style.backgroundColor="#fff"}
? ? ? ? }
}
? ? function bgcChange(a){
? ? ? ? a.style.backgroundColor="red";
? ? }
2016-10-30
如果直接這么寫:
這里bgcChange是一個(gè)自執(zhí)行函數(shù),而并不是事件函數(shù),因此一加載頁(yè)面就會(huì)執(zhí)行;
但也不能這么寫:
這么也i值為定數(shù)(i為trlist.length),因此要寫成你的mouseout事件的格式,用this.
2016-10-30
方便把全部代碼貼出來(lái)嗎
2016-10-29
this就是代表trlist[i],然后this.style.backgroundColor=“red”就是直接給他們每一個(gè)都設(shè)置了顏色!
function bgcChange(a){
? ? ? ? a.style.backgroundColor="red";
? ? }
這個(gè)函數(shù)和
?trlist[i].onmouseout=function(){this.style.backgroundColor="#fff"}只要一個(gè)就好了
你用了兩種方法設(shè)置了顏色
2016-10-29
因?yàn)閣indow.onload意思就是頁(yè)面一加載就運(yùn)行!bgcChange(trlist[i]);調(diào)用了函數(shù)? function bgcChange(a)所以為紅色