一.模态框的正常点击出现,如添加功能
<td width="120px">
<button type="button class="btn btn-blue" style="width: 100px;"
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>
<h4 class="modal-title">添加</h4>
</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" style="width: 100px;"
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>
<h4 class="modal-title">修改</h4>
</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模态框案例解析,希望对大家有所帮助