<!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);
}
}
//以上为通用函数
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);我要用循环给数组添加,每个key对应一个describe,但是我循环完后想看看数组添加了多少,理论上应该有4项,但是弹出窗口显示0
添加回答
举报
0/150
提交
取消