把script放在后面就行了,因为页面上控件还没加载
所以找不到对象,报错!<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name=f1>
 <input name="textfield" type="text" value="111">
</form>
<form name=f2>
 <input name="textfield2" type="text" value="222"> <SCRIPT LANGUAGE=JavaScript>
  var ff = document.forms.length
  document.writeln(ff)
  document.writeln(document.f1.textfield.value)
</SCRIPT></form>
</body>
</html>

解决方案 »

  1.   

    把script放在后面就行了,因为页面上控件还没加载
    所以找不到对象,报错!<html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body>
    <form name=f1>
     <input name="textfield" type="text" value="111">
    </form>
    <form name=f2>
     <input name="textfield2" type="text" value="222"> <SCRIPT LANGUAGE=JavaScript>
      var ff = document.forms.length
      document.writeln(ff)
      document.writeln(document.f1.textfield.value)
    </SCRIPT></form>
    </body>
    </html>