var box = document.getElementById('box')
    box.onclick = function() {
        this.style.backgroundColor = 'red'
    }
    //正确

    var box = document.getElementById('box')
    box.onclick = function() {
        setTimeout(function() {
            this.style.backgroundColor = 'red'
        })
    }
    //错误  Cannot set property 'backgroundColor' of undefined
    //这里this指的是 window 无style

你的闲暇往往定你的终身

标签云

友情链接