Bootstrap模态框使用详解

发布时间:2020-10-06 02:25:30 作者:风轻云淡观自在
来源:脚本之家 阅读:164

本文实例为大家分享了Bootstrap模态框的两种使用状况,供大家参考,具体内容如下

一.模态框的正常点击出现,如添加功能

<td width="120px">
  <button type="button class="btn btn-blue" 
data-toggle="modal" data-target="#systemAdd">添加</button></td>


<!-- 添加的模态框 --> </aside>
      <div class="modal fade" id="systemAdd" role="dialog">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header modal-header-blue">
              <button type="button" class="close" data-dismiss="modal"
                aria-hidden="true">&times;</button>
              <h5 class="modal-title">添加</h5>
            </div>
            <div class="modal-body text-center">
              <form role="form-horizontal"
                action="${ctx}/system/addSystemUser.xht" method="post"
                id="addForm">

                <div class="form-group">
                  <label for="name">用户ID</label> <input type="text"
                    class="form-control" id="userId0" name="userId"
                    placeholder="请输入用户ID">
                </div>

                <div class="form-group">
                  <label for="name">密码</label> <input type="text"
                    class="form-control" id="userPwd" name="userPwd"
                    placeholder="请输入密码">
                </div>
                <div class="form-group">
                  <label for="name">系统ID</label> <input type="text"
                    class="form-control" id="systemCode" name="systemCode"
                    placeholder="请输入系统ID">
                </div>
                <div class="form-group">
                  <label for="name">是否是管理员</label> <select class="form-control "
                    id="superFlg" name="superFlg">
                    <option value="0">否</option>
                    <option value="1">是</option>

                  </select>
                </div>
                <div class="form-group">
                  <label for="name">删除标志</label> <select class="form-control "
                    id="delFlg" name="delFlg">
                    <option value="0">正常</option>
                    <option value="1">删除</option>

                  </select>
                </div>
                <div class="form-group">
                  <label for="name">创建日期</label>
                  <div class='input-group date' id='datetimepicker1'>

                    <input type='text' class="form-control" placeholder="请选择创建日期"
                      data-date-format="YYYY-MM-DD HH:mm:ss" id="createTime"
                      name="createTime" /> <span class="input-group-addon">
                      <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                  </div>
                </div>

              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-blue" data-dismiss="modal"
                onclick="addSystemUser()">添加</button>
              <button type="button" class="btn btn-default"
                data-dismiss="modal">关闭</button>
            </div>
          </div>
        </div>
      </div>

二.还有一种就是编辑,此时在弹出模态框时,里面要写入数据,所以要先取得数据再弹出模态框。这时要加入js代码控制

1.jsp页面

<td width="120px">
   <button type="button "
    class="btn btn-green" 
    onclick="updateSystemUser()">修改</button></td>



<div class="modal fade" id="systemUpp" role="dialog">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header modal-header-green">
              <button type="button" class="close" data-dismiss="modal"
                aria-hidden="true">&times;</button>
              <h5 class="modal-title">修改</h5>
            </div>
            <div class="modal-body text-center">
              <form role="form-horizontal"
                action="${ctx}/system/updateUser.xht" method="post"
                id="modifyForm">
                <div class="form-group" hidden="hidden">
                  <label for="name">NO</label> <input type="text"
                    class="form-control" id="no1" name="no" readonly>
                </div>
                <div class="form-group" hidden="hidden">
                  <label for="name">用户ID</label> <input type="text"
                    class="form-control" id="userId1" name="userId" readonly
                    placeholder="请输入用户ID">
                </div>
                <div class="form-group">
                  <label for="name">用户名</label> <input type="text"
                    class="form-control" id="userName1" name="userName"
                    placeholder="请输入用户名">
                </div>
                <div class="form-group" hidden="hidden">
                  <label for="name">密码</label> <input type="text"
                    class="form-control" id="userPwd1" name="userPwd"
                    placeholder="请输入密码">
                </div>
                <div class="form-group">
                  <label for="name">系统ID</label> <input type="text"
                    class="form-control" id="systemCode1" name="systemCode"
                    placeholder="请输入系统ID">
                </div>
                <div class="form-group" hidden="hidden">
                  <label for="name">是否是管理员</label> <select class="form-control "
                    id="superFlg1" name="superFlg">
                    <option value="0">否</option>
                    <option value="1">是</option>

                  </select>
                </div>
                <div class="form-group">
                  <label for="name">删除标志</label> <select class="form-control "
                    id="delFlg1" name="delFlg">
                    <option value="0">正常</option>
                    <option value="1">删除</option>

                  </select>
                </div>
                <div class="form-group" hidden="hidden">
                  <label for="name">创建日期</label>
                  <div class='input-group date' id='datetimepicker3'>
                    <input type='text' class="form-control"
                      data-date-format="YYYY-MM-DD HH:mm:ss" id="createTime1"
                      name="createTime" placeholder="请选择创建日期" /> <span
                      class="input-group-addon"> <span
                      class="glyphicon glyphicon-calendar"></span>
                    </span>
                  </div>
                </div>
              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-green" data-dismiss="modal"
                onclick="modifySystemUser()">修改</button>
              <button type="button" class="btn btn-default"
                data-dismiss="modal">关闭</button>
            </div>
          </div>
        </div>
      </div>

2.js代码

/**
 * 修改用户(将用户信息写入模态框)
 */
function updateSystemUser() {

  var tempInput = new Input();
  tempInput.userId = $('input[name="userId"]:checked').val();
  if (tempInput.userId == null) {
    alert("请选择一条数据来修改");
  } else {

    var params = JSON2.stringify(tempInput);
    var url = "/emailplatform/system/selectOneUser.xht";
    ajaxJson(url, true, params, function(reObject) {

      // 开启模态框
      var dialog = $('#systemUpp').modal({
        backdrop : 'static',
        keyboard : false
      });
      dialog.modal('show');
      if (reObject) {
        $("#no1").val(reObject.data.no);
        $("#userId1").val(reObject.data.userId);
        $("#userName1").val(reObject.data.userName);
        $("#userPwd1").val(reObject.data.userPwd);
        $("#systemCode1").val(reObject.data.systemCode);
        $("#superFlg1").val(reObject.data.superFlg);
        $("#delFlg1").val(reObject.data.delFlg);
        $("#createTime1").val(reObject.data.createTime);

      }

    });

  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

推荐阅读:
  1. bootstrap 模态框
  2. Bootstrap 模态框插件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

bootstrap 模态框

上一篇:nc模拟浏览器请求http

下一篇:Android实现EventBus登录界面与传值(粘性事件)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》