關(guān)于改變顏色作用域的問題
? ? ? window.onload = function(){
? ? ? ? ?changeColor() ?;?
? ? ? ? ?var trNode = document.getElementsByTagName('tr');
? ? ?// 鼠標(biāo)移動改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。
? ? ?function changeColor(){
? ? ? for (var i = 0;i<trNode.length;i++) {
? ? ? trNode[i].onmouseover = function(){
? ? ? this.style.backgroundColor = ' #f2f2f2';//為什么用this而trNode[i]不行
? ? ?
? ? ? }
? ? ? trNode[i].onmouseout = function(){
? ? ? this.style.backgroundColor = '#fff';
? ? ? }
? ? ? }
? ? ?}
?
}?
this.style.backgroundColor = ' #f2f2f2';?
this.style.backgroundColor = '#fff';
這兩句為什么用this而trNode[i]不行
2018-11-29
onmouseover是一個事件函數(shù),函數(shù)里面調(diào)不到外面的循環(huán)變量。。