在事件切换器的时候,我在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
求指导,为啥不行,不理解
相关分类