zoukankan      html  css  js  c++  java
  • JS-校验表单后提交表单的三种方法总结

    第一种:

    <script type="text/javascript">
             function check(form) {
    
              if(form.userId.value=='') {
                    alert("请输入用户帐号!");
                    form.userId.focus();
                    return false;
               }
           if(form.password.value==''){
                    alert("请输入登录密码!");
                    form.password.focus();
                    return false;
             }
             return true;
             }
    </script>
    <form action="login.do?act=login" method="post">
    用户帐号
      <input type=text name="userId" size="18" value="" >
    <br>
     登录密码      
    <input type="password" name="password" size="19" value=""/>      
     <input type=submit name="submit1" value="登陆" onclick="return check(this.form)"> 
    </form>   
     

    第二种:

    <script type="text/javascript">
             function check(form) {
    
              if(form.userId.value=='') {
                    alert("请输入用户帐号!");
                    form.userId.focus();
                    return false;
               }
           if(form.password.value==''){
                    alert("请输入登录密码!");
                    form.password.focus();
                    return false;
             }
             return true;
             }
    </script>
    <form action="login.do?act=login" method="post" onsubmit="return check(this)">
    用户帐号
      <input type=text name="userId" size="18" value="" >
    <br>
     登录密码      
    <input type="password" name="password" size="19" value=""/>      
     <input type=submit name="submit1" value="登陆"> 
    </form>  

    第三种:

    <script type="text/javascript">
             function check(form) {
    
              if(form.userId.value=='') {
                    alert("请输入用户帐号!");
                    form.userId.focus();
                    return false;
               }
           if(form.password.value==''){
                    alert("请输入登录密码!");
                    form.password.focus();
                    return false;
             }
    
              document.myform.submit();
    }
    </script>
    <form action="login.do?act=login" name="myform" method="post">
    用户帐号
      <input type=text name="userId" size="18" value="" >
    <br>
     登录密码      
    <input type="password" name="password" size="19" value=""/>      
    <input type=button name="submit1" value="登陆" onclick="check(this.form)"> 
    </form> 
  • 相关阅读:
    behavior planning——15.cost function design weightTweaking
    behavior planning——14.implement a cost function in C++
    behavior planning——13. implement a cost function in C++
    behavior planning——12.example cost funtion -lane change penalty
    发布全局项目
    http
    网址大全
    JSON.parse()和JSON.stringify()
    Ajax+Node分页
    H5移动端的注意细节
  • 原文地址:https://www.cnblogs.com/shenyangxiaohuo/p/5233199.html
Copyright © 2011-2022 走看看