<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1> 这是练习</h1>
<p>
The <abbr title="我是第1个title">W3C</abbr>
</p>
<p>我是内容,我是内容,我是内容,我是内容,我是内容</p>
<p>
The <abbr title="我是第2个title">XTm</abbr>
</p>
<script>
function addLoadEvent(func){
var oldonload=window.onload;
if(typeof window.onload!='function'){
window.onload=func
}else{
window.onload=function(){
oldonload()
func()
}
}
}
function displayAbbreviations(){
var abbreviations=document.getElementsByTagName("abbr");
if (abbreviations.length<1) return false;
var getarray=new Array;
for (var i = 0; i < abbreviations.length; i++) {
var gettitle=abbreviations[i].getAttribute("title")
var gettext=abbreviations[i].lastChild.nodeValue;
getarray[gettext]=gettitle
};
var getd1=document.createElement("d1")
for(gettext in getarray){
var gettitle=getarray[gettext]
var d=document.createElement("dt")
var d_text=document.createTextNode(gettext)
d.appendChild(d_text);
var t=document.createElement("dd")
var t_text=document.createTextNode(gettitle);
t.appendChild(t_text);
getd1.appendChild(d);
getd1.appendChild(t);
}
}
addLoadEvent(displayAbbreviations)
</script>
</body>
</html>
相关分类