List of abbreviations function
HTML structure:
<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Show List of abbreviations</title><style>Body{font-family:"Helvetiva", "Arial", Sans-serif;font-size:10pt;}abbr{Border:0;Font-style:Normal;} </style></Head><Body> <H1>What is the Document Object Model?</H1> <P>The<abbrtitle= "World wide Web Consortium">W3c</abbr>Defines the<abbrtitle= "Document Object Model">Dom</abbr>As</P><blockquotecite= "http://www.w3.org/DOM/"><P>A platform and language-neutral interface that would allow programs and scripts to dynamically access and update the Conten T, structure and style of documents.</P></blockquote><P>IT 's an<abbrtitle= "Application Programming Interface">Api</abbr>That can is used to navigate<abbrtitle= "Hypertext Markup Language">Html</abbr>and<abbrtitle= "Extensible Markup Language">Xml</abbr>Documents.</P> <Scriptsrc= "Scripts/addloadevent.js"></Script> <Scriptsrc= "Scripts/displayabbrevitions.js"></Script></Body></HTML>
Js:
functionAddloadevent (func) {varOldonload =window.onload; if(typeofWindow.onload! = ' function ') {window.onload=func; } Else{window.onload=function() {oldonload (); Func (); } }}//Displayabbreviations.jsfunctiondisplayabbreviations () {//Get all Acronyms varAbbreviations = document.getElementsByTagName ("abbr"); if(Abbreviations.length < 1)return false; varDefs =NewArray (); //iterate through all the acronyms for(vari=0; i<abbreviations.length; i++){ varCURRENT_ABBR =Abbreviations[i]; varDefinition = Current_abbr.getattribute ("title"); varKey =Current_abbr.lastChild.nodeValue; Defs[key]=definition; } //Create a definition list varDlist = document.createelement ("DL"); //Traversal definition for(Keyinchdefs) { varDefinition =Defs[key]; //Create a definition title varDtitle = document.createelement ("DT"); varDtitle_text = document.createTextNode (key);//Here's one more quote.Dtitle.appendchild (Dtitle_text); //Create definition Description varDdesc = document.createelement ("DD"); varDdesc_text = document.createTextNode ("definition")); Ddesc.appendchild (Ddesc_text); //add them to the definition listDlist.appendchild (Dtitle); Dlist.appendchild (DDESC); } //Create a title varHeader = Document.createelement ("H2"); varHeader_text = document.createTextNode ("abbreviations") Header.appendchild (Header_text); //add a title to the page bodyDocument.body.appendChild (header); //to add a definition list to a page bodyDocument.body.appendChild (dlist);} Addloadevent (displayabbreviations);
This refers to a for in statement whose function is to enumerate the properties of the object;
Syntax: for (property in expression) statement
Example: for (var propname in window) {
document.write (propname);
}
JS DOM Programming Art--display list of abbreviations--JS study notes 2015-7-16 (85th Day)