zoukankan      html  css  js  c++  java
  • jsp验证表单后再提交

    在提交表单时,我们常常需要验证核实表单内容,若都不为空时,方能提交;若有文本框为空则不提交,并获取鼠标焦点到文本框上 ,所以我们可以利用onsubmit的方法来做,请看下面例子:

    <html>

    <head><title></title>

    <script>

      function yan(){

       if(frm.stuname.value==""){

        alert("姓名不得为空!");//弹出提示框

        document.frm.stuname.focus();  //获取鼠标焦点

        return(false);//返回一个值

      }

      else if(frm.stuPWD.value==""){

        alert("密码不得为空!");//弹出提示框

        document.frm.stuPWD.focus();  //获取鼠标焦点

        return(false);//返回一个值

      }

     }

    </script>

    </head>

    <body>

       <form onsubmit="return yan()">

         <table>

              <tr>

                <td>用户名:<input type="text" id="stuname"></td>

             </tr>

            <tr>

                <td>密码:<input type="password" id="stuPWD"></td>

             </tr>

            <tr>

                <td><input type="submit" value="提交"></td>

             </tr>

               

         <table>

       </form>

    </body>

    </html>

    这样就可以了,按提交时就会触发方法,注意的是,onsubmit="return yan()",里面一定要加上return,否则没有返回值的话,方法会失效

  • 相关阅读:
    java 锁
    mybatis 基本用法
    MYSQL 数据库
    进程与线程的区别
    EJB类型
    线程创建方式
    JDBC连接数据库的基本步骤
    org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch
    Centos中的/etc/sysconfig/network-scripts/ifcfg-eth0的正确配置
    利用maven导入依赖失败的问题
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3202740.html
Copyright © 2011-2022 走看看