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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用for循環(huán)給數(shù)組添加元素,為什么用alert顯示還是長度0

用for循環(huán)給數(shù)組添加元素,為什么用alert顯示還是長度0

開心的山羊 2017-10-13 02:12:04
<!DOCTYPE?html> <html> <head> <title>縮略語列表</title> <link?rel="stylesheet"?href="tst.css"?type="text/css"?/> </head> <body> <h1>What?is?the?Document?Object?Model?</h1> <p> The?<abbr?title="World?Wide?Web?Consortium">W3C</abbr> defines?the?<abbr?title="Document?Object?Model">DOM</abbr>as: </p> <blockquote?cite="http://www.w3c.org/DOM/"> <p>A?platform?and?language-neutral?interface?that?will? allow?programs?and?scripts?to?dynamically?access?and?update the?content,structure?and?style?of?documents.</p> </blockquote> <p> It?is?an?<abbr?title="Application?Programming?Interface">API</abbr> that?can?be?used?to?navigate?<abbr?title="eXtensible?Markup?Language">XML</abbr>?document. </p> <abc></abc> <script?src="tes.js"></script> </body> </html>function?adonload(func){ var?oldonload?=?window.onload; if(typeof?oldonload?!=?'function'){ window.onload?=?func; }else{ window.onload?=?function(){ oldonload(); func(); } } } function?insertAfter(newele,tagele){ var?parent?=?tagele.parentNode; if(parent.lastChild?==?tagele){ parent.appendChild(newele); }else{ insertBefore(newele,tagele.nextSibling); } } //以上為通用函數(shù) function?displayAbbreviations(){ if(!document.getElementsByTagName)return?false; if(!document.createElement)return?false; if(!document.createTextNode)return?false; var?abbrEle?=?document.getElementsByTagName("abbr"); if(abbrEle.length?<?1)?return?false; var?defs?=?new?Array(); for(var?i?=?0;?i<abbrEle.length;?i++){ if(abbrEle[i].childNodes.length?<?1)?continue;?? var?key?=?abbrEle[i].lastChild.nodeValue; var?describe?=?abbrEle[i].getAttribute("title"); defs[key]?=?describe; //?alert(defs.length);??這里為什么不能顯示defs的長度??? } var?dlEle?=?document.createElement("dl"); for(key?in?defs){ var?describe?=?defs[key]; var?dtEle?=?document.createElement("dt"); var?dtEleTxt?=?document.createTextNode(key); dtEle.appendChild(dtEleTxt); var?ddEle?=?document.createElement("dd"); var?ddEleTxt?=?document.createTextNode(describe); ddEle.appendChild(ddEleTxt); dlEle.appendChild(dtEle); dlEle.appendChild(ddEle); } if(dlEle.childNodes.length?<?1)return?false; document.body.appendChild(dlEle); //?alert(defs.length)???這里為什么也不能顯示defs的長度??? var?header?=?document.createElement("h2"); var?headerTxt?=?document.createTextNode("縮略語列表"); header.appendChild(headerTxt); dlEle.parentNode.insertBefore(header,dlEle); } function?displayCite(){ if(!document.getElementsByTagName)return?false; if(!document.createElement?||?!document.createTextNode)return?false; var?quote?=?document.getElementsByTagName("blockquote"); for(var?i?=?0;?i<quote.length;?i++){ if(!quote[i].getAttribute("cite"))continue; var?cite?=?quote[i].getAttribute("cite"); var?links?=?document.createElement("a"); var?linksTxt?=?document.createTextNode("source"+(i+1)); links.appendChild(linksTxt); links.setAttribute("href",cite[i]); document.body.appendChild(links); } } adonload(displayAbbreviations); adonload(displayCite);我要用循環(huán)給數(shù)組添加,每個key對應一個describe,但是我循環(huán)完后想看看數(shù)組添加了多少,理論上應該有4項,但是彈出窗口顯示0
查看完整描述

2 回答

?
__innocence

TA貢獻313條經驗 獲得超208個贊

你看看key是什么類型的,如果是字符串,那么你就不是在給數(shù)組添加元素,而是在給數(shù)組添加屬性

查看完整回答
反對 回復 2017-10-16
  • 2 回答
  • 1 關注
  • 1216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號