标签:姓名 document form set eva reset var lte value
html代码:
<body onload ="loaded12()"> <form name="form1" action="http://www.baidu.com" method="post"> 姓名:<label ><input type="text" name="name"/></label><br/> 年龄:<label ><input type="text" name="age"/></label><br/> <input type="submit" name="submit" value="提交" onclick="submitClick()" /> <input type="reset" name="reset" value="重置"/> <input type="image" name="image"> </form> <h1 id="title">好人一生平安</h1> </body>
遍历节点
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); }
改变节点的值:下面两句代码等价
document.getElementById("title").childNodes[0].nodeValue= "我是标题";
document.getElementById("title").innerHtml="我是标题";
改变属性:
document.getElementById("title").childNodes[0].nodeValue= "我是标题";//下面两句等价 document.getElementById("title").setAttribute("style","background: red;"); document.getElementById("title").style.background="red";
添加节点:
var tilte = document.getElementById("title"); img = document.createElement("IMG"); img.src="123.png"; title.appendChild(img);
标签:姓名 document form set eva reset var lte value
原文地址:http://www.cnblogs.com/hualuoshuijia/p/7380879.html