日期:2014-05-18  浏览次数:20624 次

js验证时会返回验证信息,但为什么仍会提交到下一页
是用来验证修改密码的,为什么当没有输入旧密码时,会返回提示,但仍会被提交到下一页,这是怎么回事
  <script language="javascript">
 function chk()
{  
var op=document.ps.oldp;
var np=document.ps.newp;
var np1=document.ps.newpp;
  if(op.value=="")
{alert("你没有输入旧密码");
document.ps.oldp.focus();
document.ps.oldpp.select();
return false;}
else
{  
if(np.value.length<6||np.value.length>20)
{
alert("密码长度在6~20之间");
document.ps.newp.focus();
document.ps.newp.select();
return false;}
else{
if (np1.value!=np.value)
{alert("两次密码输入不一致");
document.ps.newp.focus();
document.ps.newp.select();
return false;}
else{return true;}
}
}
}
</script>

------解决方案--------------------
你的第11行代码变量写错了
document.ps.oldp.select(); 写成了document.ps.oldpp.select(); 
写代码养成好习惯,相同变量最好复制粘贴,手写容易出错