下面这段代码当两次密码输入不同的时候应该return false;然后不提交啊。为什么alert完了以后他仍然提交呢????<script language="JavaScript" type="text/javascript" >
function check(){
if(document.myform.pw.value != document.myform.pw2.value)
{
alert("两次输入的新密码不相同");
return false;
}
}
</script>
<form action="__URL__/modpw" method="post" name="myform">
<table>
  <tr><td>用户名:</td><td><input type="text" name="name"/></td></tr>
  <tr><td>旧密码:</td><td><input type="password" name="opw"/></td></tr>
  <tr><td>新密码:</td><td><input type="password" name="pw"/></td></tr>
  <tr><td>确认新密码:</td><td><input type="password" name="pw2"/></td></tr>
</table>
  <input type="submit" name="submit" value="确定" onclick="check()"/>
  <input type="reset" name="reset" value="重置" />
</form>

解决方案 »

  1.   

    onclick返回false没用吧,应该是form标签里的onsubmit返回false才行吧,我也没什么经验。
      

  2.   

    <input type="submit" name="submit" value="确定" onclick="check();return false;"/>
      

  3.   

    <input type="submit" name="submit" value="确定" onclick="check();return false;"/>
      

  4.   


    原来是onclick="return check()"/
      

  5.   

    function check(){
    if(document.myform.pw.value != document.myform.pw2.value)
    {
    alert("两次输入的新密码不相同");
    return;
    }
    }试试
      

  6.   

    <input type="submit" name="submit" value="确定" onclick="check()"/> 写法修改下就可以了。如下:
    <input type="submit" name="submit" value="确定" onclick="check()"/> 
      

  7.   

    不能在点击按钮的时候判断,要在表单提交的时候。这样就行了:<form action="test.php" method="post" name="myform" onsubmit="return check();"><input type="submit" name="submit" value="确定"/>
      

  8.   

    把“submit”改为“buttom”提交就行了!<input type="button" name="submit" value="确定" onclick="check()"/>
      

  9.   

    把“submit”改为“buttom”,<input type="button" name="submit" value="确定" onclick="check()"/>
      

  10.   

    GOODGOODGOODGOODGOODGOODGOODGOODGOODGOODGOODGOODGOODGOODGOODGOODGOOD