javascript - this.className问题
本文介绍了javascript - 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
求指导,为啥不行,不理解
解决方案
这错的...你用的是class,却用id选择器来取怎么取的到,建议好好看下文档
这篇关于javascript - this.className问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文