我写了个js验证函数  在form标签中 onsubmit="return check()"
但是我这个页面有 返回按钮   
在我点击返回时  他和上面那个onsubmit相冲突了
 每次我点击返回的时候   他要执行验证
请问下有什么解决方法

解决方案 »

  1.   

    返回的时候也会调用onsubmit??
      

  2.   

    你的 返回按钮 是不是  type="submit" ? 如果是的话,改为:type="button" 就不会执行Check()了
      

  3.   

    JS 客户端验证是 十分不安全 的 很轻松就可以绕过去, 建议 客户端 服务器 双重验证  
       submit 也可以  Onclick的
      

  4.   

    刚没看清楚  你这样弄
     <script>
    fucntion check()
    {
      if(document.form1.txt.value=="")
        {
         alert("不能为空");
         return false;
        }
    }
    </script>
    <body>
    <form name ="form1" action="1.html">
    <p>
    <input name="txt"><br>
    <p>
    <input type="submit" value="提交" onclick ="renturn check()"/>
    </form>
    </body>
    但是这样验证是十分不安全的 建议加客户端验证
      

  5.   

    <script>
    fucntion check()
    {
      if(document.form1.txt.value=="")
        {
         alert("不能为空");
         return false;
        }
    }
    </script>
    <body>
    <form name ="form1" action="1.html">
    <p>
    <input name="txt"><br>
    <p>
    <input type="submit" value="提交" onclick ="renturn check()"/>
    <input type="button" value="取消" onclick =" "/>
    </form>
    </body>
      

  6.   

    把函数写到服务器控件事件就可以了<script> 
    fucntion check() 

      if(document.form1.txt.value=="") 
        { 
        alert("不能为空"); 
        return false; 
        } 

    </script> 
    <body> 
    <form name ="form1" action="1.html"> 
    <p> 
    <input name="txt"> <br> 
    <p> 
    <input type="submit" value="提交" onClientclick ="renturn check()"/> 
    <input type="button" value="取消" onclick =" "/> 
    </form> 
    </body>