您好,登錄后才能下訂單哦!
以下body部分:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Explaining the Ddocument Ob Model</title> <link href="style08.css" type="text/css" rel="stylesheet" /> </head> <body> <h2> What is the Document object Model?</h2> <p> The <abbr title="Worle Wide Web Consortium">W3C</abbr> defines the <abbr title="Object Model">DOM</abbr> as: </p> <blockquote cite="http://www.w3.org/DOM/"> <P> A platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content,structure and styles 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> documents. </p> <script src="test.js"></script> </body> </html>
以下是js部分:
function addLoadEvent(func){ //不管在頁(yè)面加載完畢執(zhí)行多少個(gè)函數(shù),都應(yīng)付自如 var oldonload = window.onload; if(typeof window.onload != 'function'){ window.onload = func; }else{ window.onload = function(){ oldonload(); func(); } } } function displayAbbreviations(){ //檢查兼容性 if(!document.getElementsByTagName||!document.createElement||!document.createTextNode) return false; var abbreviations = document.getElementsByTagName("abbr"); //取得所有縮略詞 if(abbreviations.length < 1) return false; var defs = new Array(); for(var i=0; i < abbreviations.length; i++){ //遍歷這些縮略詞 var current_abbr = abbreviations[i]; var definition = current_abbr.getAttribute("title"); var key = current_abbr.lastChild.nodeValue; defs[key] = definition; } var dlist = document.createElement("dl"); //創(chuàng)建定義列表 for( key in defs){ //遍歷定義 var definition = defs[key]; var dtitle = document.createElement("dt"); //創(chuàng)建定義標(biāo)題 var dtitle_text = document.createTextNode(key); dtitle.appendChild(dtitle_text); var ddesc = document.createElement("dd"); //創(chuàng)建定義描述 var ddesc_text = document.createTextNode(definition); ddesc.appendChild(ddesc_text); //把它們添加到定義列表 dlist.appendChild(dtitle); dlist.appendChild(ddesc); } var header = document.createElement("h3"); //創(chuàng)建標(biāo)題 var header_text = document.createTextNode("Abbreviations"); header.appendChild(header_text); document.body.appendChild(header); //把標(biāo)題添加到頁(yè)面主體 document.body.appendChild(dlist); //把定義列表添加到主體 } addLoadEvent(displayAbbreviations);
頁(yè)面預(yù)覽效果:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。