8.this指向

1.注意

function fn1(){
    alert(this);
}

oBtn.onclick = function(){
    fn1();    // 弹出的是objet window
};


/***********************/
function fn1(obj){
    alert(obj);
}

oBtn.onclick = function(){
    fn1(this);    // 弹出的是oBtn
};

2.跨函数应用

var that = null;

oBtn.onclick = function(){
    that = this;
    fn1();
};
function fn1(){
    that.style.background = 'red';
}
JSRUN notes