課程
/前端開發
/JavaScript
/側邊欄信息展示效果
sideBar.js:8 Uncaught TypeError: Cannot read property 'addEventListener' of null
2016-08-26
源自:側邊欄信息展示效果 3-1
正在回答
(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(); ?? ?})();
夕顏egao
你把所有的都給我,給我一部分我也沒法調
if (this.state==="opened") {this.close();}else{this.open();}};
方法要加括號?
言長寸短 提問者
見圖
貼源碼
舉報
頂級大牛分享開發經驗,學會實現側邊欄內容效果展示,讓你迅速進階
1 回答transform的問題
1 回答bootstrap的使用問題
3 回答代碼存在的問題
1 回答關于添加className的問題
1 回答sideBar那的點擊事件問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-09-05
2016-08-28
你把所有的都給我,給我一部分我也沒法調
2016-08-27
if (this.state==="opened") {this.close();}else{this.open();}};
方法要加括號?
2016-08-26
見圖
2016-08-26
貼源碼