第一个 return false;
第二个 return true;

解决方案 »

  1.   

    我最开始就是这样写的阿,第一个 return false;第二个return true;结果表单老是能够提交,后来才改成两次都return false的,我想这回总不能提交了吧,但是一试还是能提交,真的不知道错在哪里了
      

  2.   

    最开始的时候就是因为像楼上说的那样第一个return false;第二个return true;当我在不输入任何值的时候表单总是能够提交,后来才想到将两个return 都写成return false;可是表单还是能够提交,这是为什么啊?
      

  3.   

    我的源代码如下:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>忘记密码</title>
    <link rel=stylesheet href="Control.css" type="text/css">
    <!--#include file="ConToDB.inc"-->
    <script language="javascript">
    function check()
    { alert("test");
    if(form1.UserName.value=="")
    {
    alert("请输入用户名!");
    return false;
    }
    return false;

    }
    </script>
    <%  'response.Write  request.form("submit1")="确定"
    if request.form("submit1")="确定" then
    dim sqlStr
    sqlStr="select PwdKey,PwdQue from UserReg where UserName='"& request.form("UserName") &"'"
    'response.Write sqlStr
    'response.End()
    set rs=con.execute(sqlstr)
    if rs.eof and rs.bof then
    response.Write "<script language=javascript>"
    response.Write "alert('对不起,您输入的用户名并不存在!');"
    response.Write "</script>"
    'response.Redirect("ForgetPWD.asp")
    else
    response.Write "ok"
    response.End()
    end if
    end if
    'response.End()
    %>
    </head><body>
    <!--#include file="includefiles/heads.inc"-->
    <table width="780"  align="center">
    <tr>
    <!--#include file="includefiles/UserLeft.inc"-->
    <td align="center" valign="top" background="picture/BackGround/bg_ok.gif"> <table width="65%"  height="100%">
    <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
    <td align="center" colspan="2"><span style="font-size:16px;font-weight:bold;color:red;"> 取回密码:</span></td>
    </tr>
    <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
    <form action="" method="post" name="form1">
    <tr>
    <td align="right">请输入您的用户名 :</td>
    <td align="left" valign="bottom">
    <input type="text" name="UserName">&nbsp;
    <input type="submit" name="submit1" value="确定" onClick="return check();">
    </td>
    </tr>
    </form>
    <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
    </table>

    </td>
    </tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    </table><!--#include file="includefiles/cauda.inc"-->
    </body>
    </html>
      

  4.   

    我把这段代码拷贝到 Editplus 2里面也不会提交的,拷贝进去以后我把第二个 return 改成true了,当文本框里面什么也不输时,确实不能提交,可是通过iis运行该页面就可以提交呢,真是搞糊涂了,我的其他页面通过iis运行时javascript都能够进行正确判断,真晕啊
      

  5.   

    <input type="submit" name="submit1" value="确定" onClick="return check();">
    不要用submit,改为button
      

  6.   

    为空时不会提交的,不过最好别用submit类型,改button类型,用代码提交 form1.submit()
      

  7.   

    试一试:
    <script language="javascript">
    function check()
    {
    if(form1.UserName.value=="")
    {
    alert("请输入用户名!");
    return false;
    }
    form1.submit();
    }
    </script>
       .
       .
       .
    <form action="" method="post" name="form1">
         <tr>
    <td align="right">请输入您的用户名 :</td>
    <td align="left" valign="bottom">
        <input type="text" name="UserName">&nbsp;
        <input type="button" name="sss" value="确定" onclick="check();">
             </td>
         </tr>
    </form>
     
    按你说的,可能是由于缓存的影响。
      

  8.   

    你用return的方法即使脚本里面有错误也会提交的,因为没执行完。检查方法可以
    工具——INTERNET选项——高级——显示每个脚本的错误消息
    看看是不是程序错误
      

  9.   

    其实你的问题出在
    你用的是按钮是submit
    不管你调用的函数结果如何
    都会跳到action指定的页面结论是
    如果你做的是客户端验证的话
    提交按钮的type最好是command类型