日期:2014-05-16  浏览次数:20312 次

用dom访问页面元素,FF中正常,在IE中只能访问第一个?
<script   language= "javascript ">
function   post(){
var   f=document.getElementById( "form1 ");
//alert(f.childNodes.length);
for(var   i=0;i <f.childNodes.length;i++){
document.write(f.childNodes[i].nodeName);
                  }
}
</script>
<body>
<form   id= "form1 "   name= "form1 "   method= "post ">
    <input   type= "text "   name= "sex "       />
    <input   type= "text "   name= "money "   />
    <select   name= "se ">
    <option> 1 </option>
    <option> 2 </option>
    <option> 3 </option>
    </select>
    <input   name= "submit "   type= "button "   value= "go "   onclick= "post() "   />
</form>
</body>
ff可以正常运行,ie中for循环执行一次就没有了。。。。无语中

------解决方案--------------------
问题是由 document.write() 引起的,因为在页面onload之后你再使用 document.write() 的话那会把页面里的所有内容都冲掉,所以改成 alert(f.childNodes[i].nodeName); 就好了。