您好,登錄后才能下訂單哦!
這篇文章主要介紹了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">×</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">×</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); } }); } }
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Bootstrap模態框的示例分析”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。