JS DOM Programming Art--display list of abbreviations--JS study notes 2015-7-16 (85th Day)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.