bootstrap表单怎么提交信息


本文摘自PHP中文网,作者尚,侵删。

当输入用户名和密码为空的时候,需要判断。这时候就用到了校验用户名和密码,这个需要在jsp的前端页面写;有两种方法,一种是用submit提交。一种是用button提交。

方法一:

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

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表单里写成这样:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<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"  />

方法二:

1

2

3

4

5

6

7

8

9

10

11

12

13

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

1

<form id="formid" method = 'post'  action = 'user_login_submit.action'  >

button按钮的写法如下:

1

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

推荐:bootstrap入门教程

以上就是bootstrap表单怎么提交信息的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

bootstrap怎么添加背景图片

bootstrap怎么进行响应式

bootstrap有哪些技术特点

bootstrap如何设置字体

使用bootstrap-table实现分页和排序

bootstrap做的网站有哪些

浅谈bootstrap表单验证插件bootstrapvalidator

bootstrap前端视图中如何实现页面内容模块化的隔离

bootstrap怎么把div变成一个圆

bootstrap学习之表单格式与字体图标

更多相关阅读请进入《bootstrap》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...