zoukankan      html  css  js  c++  java
  • form表单的两种提交方式,submit和button的用法

    一种是用submit提交。一种是用button提交。
    方法一:

    在jsp的前端页面的头部插入一个js方法:

     function checkUser(){
       var result = document.getElementById("userid").value;
       var password = document.getElementById("userpassid").value;
       if(result == ""  ){
         alert("用户名不能为空");
         return false;
       }
       if(password == ""  ){
        alert("密码不能为空");
         return false;
       }else{
       return true;
       }
    }

    在form表单里写成这样:

    <form id="formid"  name= "myform" method = 'post'  action = 'user_login_submit.action' onsubmit = "return checkUser();" >
                <table width="100%" border="0">
                  <tr>
                    <td width="60" height="40" align="right">用户名&nbsp;</td>
                    <td><input type="text" value="" class="text2" name = "username" id = "userid"/></td>
                  </tr>
                  <tr>
                    <td width="60" height="40" align="right">密&nbsp;&nbsp;码&nbsp;</td>
                    <td><input type="password" value="" class="text2" name = "userpass" id = "userpassid"/></td>
                  </tr>
                  <tr>
                    <td width="60" height="40" align="right">&nbsp;</td>
                    <td><div class="c4">
                        <input type="submit" value="" class="btn2"  />

     

    方法二:

    button 提交

    function checkUser(){
       var result = document.getElementById("userid").value;
       var password = document.getElementById("passid").value;

       if(result == ""  ){
         alert("用户名不能为空");
         return false;
       }
       if(password == ""  ){
        alert("密码不能为空");
         return false;
       }
      document.getElementById("formid").submit();
    }

    form表格的写法,需要写id
     <form id="formid" method = 'post'  action = 'user_login_submit.action'  >

    button按钮的写法如下:

    <input type="button" value="" class="btn2" onclick = "checkUser();" />

  • 相关阅读:
    RabbitMQ安装(发生系统错误5。拒绝访问。发生系统错误1067。进程意外终止。)
    SQLServer执行脚本提示“系统找不到指定的文件”或“内存资源不足”
    TypeScript@HelloWorld!
    超详细Node安装教程
    进制转换
    菜鸟成长记
    ASP.NET Core中使用MialKit实现邮件发送
    VS未能正确加载 ”Microsoft.VisualStudio.Editor.Implementation.EditorPackate“包错误解决方法
    C#Winfrom Listview数据导入Excel
    安装研发服务器
  • 原文地址:https://www.cnblogs.com/go4mi/p/5491600.html
Copyright © 2011-2022 走看看