for语句后代码无法执行

xyun0391 2014-10-04 10:22:45
for (var i=0; i<tabObj.rows.length;i++)
{
if (document.getElementsByName('dunwei')[i].value=="22T")
{
if (document.getElementsByName('jianum')[i].value=="")
{
alert("请输入架号!");
document.getElementsByName('jianum')[i].focus();
return false;
}

}

}
if (frmcarqb.userpass.value=="")
{alert("请输入密码!");
document.frmcarqb.userpass.focus();
return false;
}

for语句后,无法执行下面的if(frmcarqb.userpass.value==""),请高手指点错在哪里?
...全文
276 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2014-10-10
  • 打赏
  • 举报
回复
标准浏览器引用表单要加上document对象,不能直接表单名称.表单项目 if (document.frmcarqb.userpass.value == "") { alert("请输入密码!"); document.frmcarqb.userpass.focus(); return false; }
Msxindl_Com 2014-10-09
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>测试文档</title>
<script type="text/javascript">
function checkform(){
	var dw=document.getElementsByName("dunwei");
	var jh=document.getElementsByName("jianum");
	for(var i=0;i<dw.length;i++){  //或jh.length
		if(dw[i].value=="22T"){
			if(jh[i].value==""){
				alert("请输入架号!");
				jh[i].focus();
				return false;
			}
		}
	}
	if (frmcarqb.userpass.value==""){
		alert("请输入密码!");
		frmcarqb.userpass.focus();
		return false;
	}
}
</script>
</head>
<body>
<form name="frmcarqb" action="" onsubmit="return checkform()" method="get">
<table name="tabObj" border="1" align="center">
<tr><td>吨位:<input type="text" name="dunwei" value="20T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>吨位:<input type="text" name="dunwei" value="21T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>吨位:<input type="text" name="dunwei" value="22T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>吨位:<input type="text" name="dunwei" value="23T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>密码:<input type="password" name="userpass" value="" />  <input type="submit" value=" 提 交 " />  <input type="reset" value=" 重填 " /></td></tr>
</table>
</form>
</body>
</html>
save4me 2014-10-09
  • 打赏
  • 举报
回复
你的代码在Chrome 34和IE 11中都没有问题,你使用的浏览器是什么版本的 在线演示代码
引用 4 楼 liaitan 的回复:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>测试文档</title>
<script type="text/javascript">
function checkform(){
	var dw=document.getElementsByName("dunwei");
	var jh=document.getElementsByName("jianum");
	for(var i=0;i<dw.length;i++){  //或jh.length
		if(dw[i].value=="22T"){
			if(jh[i].value==""){
				alert("请输入架号!");
				jh[i].focus();
				return false;
			}
		}
	}
	if (frmcarqb.userpass.value==""){
		alert("请输入密码!");
		frmcarqb.userpass.focus();
		return false;
	}
}
</script>
</head>
<body>
<form name="frmcarqb" action="" onsubmit="return checkform()" method="get">
<table name="tabObj" border="1" align="center">
<tr><td>吨位:<input type="text" name="dunwei" value="20T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>吨位:<input type="text" name="dunwei" value="21T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>吨位:<input type="text" name="dunwei" value="22T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>吨位:<input type="text" name="dunwei" value="23T" /> 架号:<input type="text" name="jianum" value="" /></td></tr>
<tr><td>密码:<input type="password" name="userpass" value="" />  <input type="submit" value=" 提 交 " />  <input type="reset" value=" 重填 " /></td></tr>
</table>
</form>
</body>
</html>
Msxindl_Com 2014-10-09
  • 打赏
  • 举报
回复
引用 5 楼 save4me 的回复:
你的代码在Chrome 34和IE 11中都没有问题,你使用的浏览器是什么版本的
360安全浏览器7.1
xyun0391 2014-10-07
  • 打赏
  • 举报
回复
getElementsByName返回的是个数组,因为是动态添加的表格行内信息
save4me 2014-10-07
  • 打赏
  • 举报
回复
把你的完整代码贴出来,你的变量tabObj.rows,frmcarqb.userpass都是怎么定义的?
引用 2 楼 xyun0391 的回复:
getElementsByName返回的是个数组,因为是动态添加的表格行内信息
save4me 2014-10-04
  • 打赏
  • 举报
回复
两种可能:架号为空或者for部分的代码执行出错,导致后续代码不能执行。 getElementsByName返回的是个数组,它本身跟tabObj.rows没有必然联系,所以长度uyiding相等。另外这个函数是否有兼容性问题。 在浏览器按F12打开开发者工具,在控制台看有没有报错。

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧