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