两个问题其实是一样的:
function show()
{
  
  document.write(document.form1.length);
//OK
  document.write(document.form1.length);
// ERROR: 文件中没有名字为form1的元素,为什么?
// 因为文件已经被你改写:document.write...
// 只有你刚刚写进去的内容--原文件中form1的length!
}

解决方案 »

  1.   

    谢谢 onestab(┼─) 
    那么为什么文件会被修改,只有length?
    万分感谢!
      

  2.   

    1. do not use document.write once the file is loaded, use something like<script>
    function show()
    {
      dv.innerHTML = document.form1.length;   
    }</script>
    <div id="dv"></div>2. in javascript, an array's index is 0 based, tryfor(i=0;i<document.form1.length;i++)
       document.write(form1.elements[i].id);
      

  3.   

    1.
    function show()
    {
      document.write(document.form1.elements.length);
    }
    去掉一个就行了
    2.
    function show1()
    {
    for(i=0;i<=document.form1.elements.length;i++)
      document.write(form1.elements[i].id);
    }加上 elements 就好了
      

  4.   

    还有一个小毛病:function show1()
    {
       for(i=0;i<document.form1.elements.length;i++)
         document.write(form1.elements[i].id);
    }<= 改成 <
    否则下标会溢出
      

  5.   

    document.write这个语句就好象是打开了一个新的页面,然后往里面写东西,你写个什么东西,这个页面就只有什么东西。呵呵,这个方法可以用来打开的一个新的页面的,如:document.write("")