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

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

as[i].style.background="#fcc“為什么會(huì)報(bào)錯(cuò)呢?代碼中下劃線部分,和作用域有關(guān)嗎

for(i=0,j=as.length;i<j;i++){

? ?//for (i in as){//用for in不行嗎,會(huì)打出prototype

? ? ? eventUtil.addEvent(as[i],"mouseover",function(){

? ? ? ? resetIndex();

? ? ? ? //用as[i]不行嗎

? ? ? ? this.style.background="#fcc";

? ? ? ? //as[i].style.background="#fcc";//Uncaught TypeError: Cannot set property 'background' of undefined at HTMLAnchorElement.<anonymous>?

? ? ? });

? ? ? eventUtil.addEvent(as[i],"mouseout",function(){

? ? ? ? this.style.background="#fff";

? ? ? });

? ? ? eventUtil.addEvent(as[i],"click",function(){

? ? ? ? console.log(mouseIndex);

? ? ? ? title.innerHTML=this.innerHTML;

? ? ? })

? ?}

? ?eventUtil.addEvent(document,"click",function(){

? ? ?menu.style.display="none";

? ? ?//eventUtil.stopPropagation(document);

? ?});

? ?eventUtil.addEvent(title,"click",function(e){

? ? ?menu.style.display="block";

? ? ?eventUtil.stopPropagation(e);

? ?});


正在回答

1 回答

這個(gè)是關(guān)于for循環(huán)里的閉包的知識(shí),你打印一下就會(huì)發(fā)現(xiàn)每次執(zhí)行的時(shí)候i的值都是as.length,所以會(huì)報(bào)錯(cuò)。幫你找了篇文章,簡(jiǎn)單看一下就知道原因了。

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

Emily夢(mèng) 提問(wèn)者

非常感謝!
2017-03-20 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

as[i].style.background="#fcc“為什么會(huì)報(bào)錯(cuò)呢?代碼中下劃線部分,和作用域有關(guān)嗎

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

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

幫助反饋 APP下載

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

公眾號(hào)

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