我想知道.childNodes
属性,我有下面的代码,由于某种原因,我得到18个孩子,而6个是HTMLInputElement
s如预期的,其余的是undefined
。这是关于什么的?有没有一种有效的方法来遍历input
元素?使用`.childNodes`从javascript访问HTML DOM元素
<html>
<head>
<script>
window.onload = function(e){
form = document.getElementById('myForm');
alert(form.childNodes.length);
for(i=0; i<form.childNodes.length; i++){
alert(form[i]);
}
}
</script>
</head>
<body>
<form id='myForm' action="haha" method="post">
Name: <input type="text" id="fnameAdd" name="name" /><br />
Phone1: <input type="text" id="phone1Add" name="phone1" /><br />
Phone2: <input type="text" id="phone2Add" name="phone2" /><br />
E-Mail: <input type="text" id="emailAdd" name="email" /><br />
Address: <input type="text" id="addressAdd" name="address" /><br />
<input type="submit" value="Save" />
</body>
</html>
只需访问www.jquery.com;他们有很好的文档。另外,如果你想要一步一步的教程只是谷歌“jQuery教程”;那里有很多东西。 – machineghost 2012-04-10 23:24:57