this.el.addEventListener 问题
sideBar.js:8 Uncaught TypeError: Cannot read property 'addEventListener' of null
sideBar.js:8 Uncaught TypeError: Cannot read property 'addEventListener' of null
2016-08-26
(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();
})();
举报