三角关系在线阅读:document.form1 自动提交表单

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 02:28:41
script……
<script language=javascript>
document.teleform.telephone.value="123456";
document.teleform.password.value="123456"
document.teleform.submit();
</script>
表单………………
<form name=teleform method="post" action="">
<input name="telephone" type="text" id="telephone">
<input name="password" type="password" id="password">
<input name="logType" type="radio" value="telephone" checked>
</form>

怎么提交不了 总提示 document.teleform.telephone 为空或不是对象

脚本代码放在表单下面:页面会先载入表单,再执行脚本程序,
你那样就是先执行脚本程序了,所以执行时表单还未下载。
<form name=teleform method="post" action="">
<input name="telephone" type="text" id="telephone">
<input name="password" type="password" id="password">
<input name="logType" type="radio" value="telephone" checked>
</form>
<script language=javascript>
document.teleform.telephone.value="123456";
document.teleform.password.value="123456"
document.teleform.submit();
</script>

你再看能不能提交!
<script language=javascript>
document.getElementById('telephone').value="123456";
document.getElementById('password').value="123456"
document.teleform.submit();
</script>

<script></script>置于teleform表单之后就可以了,网页还未加载完成就开始填充提交,当然不会找到表单对象