this.className问题

在事件切换器的时候,我在html文件写了一行代码
<div class="box">ggg</div>
css部分代码为
.box{

width:200px;height:200px;background-color:red;

}

.pox{

width:100px;height:200px;background-color:green;

}
js代码是
window.onload=function(){

var box=document.getElementById("box");box.onclick=toBlack;

};

function toBlack(){

this.className='pox';

}
但firebug说uncaught TypeError: Cannot set property 'onclick' of null
求指导,为啥不行,不理解


牧羊人nacy
浏览 733回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript