我想让它显示<form>的个数,可一直都是显示0,应该怎么改?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
document.write(document.forms.length)
</script>
</head>
<body>
<form name="form1">
<input name="a" type="text"/>
</form>
<form name="form2">
<input name="b" type="text"/>
</form>
</body>
</html>
放错地方了,你把
<script language="javascript" type="text/javascript">
document.write(document.forms.length)
</script>
这段代码放在最下面
或者用onload事件进行执行
把 <script language="javascript" type="text/javascript">
document.write(document.forms.length)
</script> 放在所有 form 标签之后。或写成 function :
******************************************************************************************
<form name="form1">
<input name="a" type="text"/>
</form>
<form name="form2">
<input name="b" type="text"/>
</form>
<script language="javascript" type="text/javascript">
document.write(document.forms.length)
</script>
**********************************************************************************************************
<script language="javascript" type="text/javascript">
function showForms(){
document.write(document.forms.length);
}
window.onload=showForms;
</script>
<form name="form1">
<input name="a" type="text"/>
</form>
<form name="form2">
<input name="b" type="text"/>
</form>
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息