在事件切换器的时候,我在html文件写了一行代码
ggg
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
求指导,为啥不行,不理解
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这错的...你用的是class,却用id选择器来取怎么取的到,建议好好看下文档
为什么要getElementByID去get一个只定义了class的元素 ?