<body onload = "loaded12 ()" ><form name= "Form1" action= "http://www.baidu.com" method= "POST" > Name: <label ><input type= "text" name= "name"/></label><br/> Age: <label ><input type= "text" name = "Age"/></label><br/> <input type= "Submit" name= "Submit" value= "commit" onclick= "Submitclick ()"/ > <input type= "reset" name= "reset" value= "reset"/> <input type= "image" Name= "image" ></form >
Traversing nodes
function loaded12 () {var txt= "", var c=document.body.childnodes;for (i=0; i<c.length; i++) { txt=txt + c[i]. NodeName + "-" + c[i].nodetype+ "-" +c[i].nodevalue+ " "; }; alert (TXT);}
Change the value of the node: The following two lines of code are equivalent
document.getElementById ("title"). Childnodes[0].nodevalue= "I am the title";
document.getElementById ("title"). Innerhtml= "I am the title";
To change a property:
document.getElementById ("title"). Childnodes[0].nodevalue= "I am the title";//The following two sentences are equivalent to document.getElementById ("title"). SetAttribute ("Style", "background:red;"); document.getElementById ("title"). style.background= "Red";
To add a node:
var tilte = document.getElementById ("title"), IMG = document.createelement ("img"), img.src= "123.png"; Title.appendchild (IMG);
JS DOM Node