第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

this.el.addEventListener 問題

sideBar.js:8 Uncaught TypeError: Cannot read property 'addEventListener' of null

正在回答

5 回答

(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();

??

?})();

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

夕顏egao

你最好把你的代碼放在window.onload里面或者最后,有可能是在js加載在id這個(gè)dom前了,這個(gè)時(shí)候的eId是undefined,所以這個(gè)時(shí)候用addeventlistener為null
2017-02-21 回復(fù) 有任何疑惑可以回復(fù)我~

你把所有的都給我,給我一部分我也沒法調(diào)

0 回復(fù) 有任何疑惑可以回復(fù)我~

if (this.state==="opened") {this.close();}else{this.open();}};

方法要加括號(hào)?

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

言長(zhǎng)寸短 提問者

這個(gè)不影響的
2016-08-28 回復(fù) 有任何疑惑可以回復(fù)我~
#2

言長(zhǎng)寸短 提問者

問題依舊存在
2016-08-28 回復(fù) 有任何疑惑可以回復(fù)我~

見圖

0 回復(fù) 有任何疑惑可以回復(fù)我~

貼源碼

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

言長(zhǎng)寸短 提問者

this.state="opened"; this.el=document.getElementById(eId||'sideBar'); alert(this.el); this.closeBar=document.getElementById(closeId||'closeBar'); var self=this; this.el.addEventListener('click',function(event){ if (event.target !== self.el){ self.triggerSwitch();
2016-08-26 回復(fù) 有任何疑惑可以回復(fù)我~
#2

言長(zhǎng)寸短 提問者

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();
2016-08-26 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
側(cè)邊欄信息展示效果
  • 參與學(xué)習(xí)       33649    人
  • 解答問題       101    個(gè)

頂級(jí)大牛分享開發(fā)經(jīng)驗(yàn),學(xué)會(huì)實(shí)現(xiàn)側(cè)邊欄內(nèi)容效果展示,讓你迅速進(jìn)階

進(jìn)入課程

this.el.addEventListener 問題

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)