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