言长寸短
2016-08-26 11:21
sideBar.js:8 Uncaught TypeError: Cannot read property 'addEventListener' of null
(function(){
var SideBar=function(eId,closeId){
this.state="opened";
this.el=document.getElementById(eId||'sideBar');
this.closeBar=document.getElementById(closeId||'closeBar');
var self=this;
this.el.addEventListener('click',function(event){
if (event.target !== self.el){
self.triggerSwitch();
}
});
};
SideBar.prototype.triggerSwitch=function(){
if (this.state==="opened") {
this.close();
}else{
this.open();
}
};
SideBar.prototype.close=function(){
this.state="closed";
};
SideBar.prototype.open=function(){
this.state=="opened";
};
var sidebar=new SideBar();
})();
你把所有的都给我,给我一部分我也没法调
if (this.state==="opened") {this.close();}else{this.open();}};
方法要加括号
见图
贴源码
侧边栏信息展示效果
33647 学习 · 101 问题
相似问题