日期:2014-05-16 浏览次数:20399 次
// JavaScript Document function displayAbbreviations(){ if(!document.getElementsByTagName||!document.createElement||!document.createTextNode) return false; //get abbr var abbreviations = document.getElementsByTagName("abbr"); if(abbreviations.length<1) return false; var defs = new Array(); //do all abbr for(var i=0; i<abbreviations.length;i++){ var current_abbr = abbreviations[i]; var defition = current_abbr.getAttribute("title"); var key = current_abbr.lastChild.nodeValue; defs[key] = defition; } //create defition list var dlist = document.createElement("dl"); //do all defition for(key in defs) { var defition = defs[key]; var dtitle = document.createElement("dt"); var dtitle_text = document.createTextNode(key); dtitle.appendChild(dtitle_text); //create defition description var ddesc = document.createElement("dd"); var ddesc_text = document.createTextNode(defition); ddesc.appendChild(ddesc_text); //add them to defition list dlist.appendChild(dtitle); dlist.appendChild(ddesc); } //create title var header = document.createElement("h2"); var header_text = document.createTextNode("Abbreviations"); header.appendChild(header_text); //add title to document body document.getElementsByTagName("body")[0].appendChlid(header); //add defition list to document body document.getElementsByTagName("body")[0].appendChlid(dlist); } addLoadEvent(displayAbbreviations);
// JavaScript Document function addLoadEvent(func){ var oldonload = window.onload; if(typeof window.onload!='function'){ window.onload = func; }else{ window.onload = function(){ oldonload(); func(); } } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="uft-8" /> <title>Explaining the Document Object Model</title> <link rel="stylesheet" media="screen" href="styles/typography.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.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 style of documents.</p></blockquote> <p>It is an <abbr title="Application Programming Interface">API</abbr> that can be used to navigate <abbr title="HyperText Markup Language">HTML</abbr> and <abbr title="eXtensible Markup Language">XML</abbr> documents.</p> <script type="text/javascript" src="scripts/addLoadEvent.js"></script> <script type="text/javascript" src="scripts/displayAbbreviations.js"></script> </b