Improvements to the picture library of JavaScript DOM programming art notes

Source: Internet
Author: User

Principles to be followed for DOM operations

1. Smooth degradation

2. Separating JavaScript

3. Backwards compatibility

4. Performance Considerations

Improved display image method

functionShowpic (whichpic) {if(!document.getelementbyid ("placeholder"))return false; varSource=whichpic.getattribute ("href"); varPlaceholder=document.getelementbyid ("placeholder"); if(placeholder.nodename!= "IMG")return false; Placeholder.setattribute ("SRC", source); if(document.getElementById ("description")){    varText=whichpic.getattribute ("title")? Whichpic.getattribute ("title"): ""; varDescription=document.getelementbyid ("description"); if(description.firstchild.nodetype==3) {Discription.firstChild.nodeValue=text; }    }    return true;}

Newly added separation of HTML and JavaScript methods

functionPreparegallery () {if(!document.getelementbyid)return false; if(!document.getelementbytagname)return false; if(!document.getelementbyid ("Imagegallery"))return false; varGallery=document.getelementbyid ("Imagegallery"); varLink=gallery.getelementbytagname ("a");  for(vari=0; I<link.length; i++) {Link[i].onclick=function(){            returnShowpic ( This) ?false:true; }    }}

Ways to add events

function Addloadevent (func) {    var oldonload=window.onload;     if (typeof window.onload!= ' function ') {        window.onload=func;    } Else {        window.onload-function() {            oldonload ();            Func ();        }    } }

Improvements to the picture library of JavaScript DOM programming art notes

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.