代码段:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 引入 Bootstrap -->
<script src="js/jquery/3.3.1/jquery.min.js"></script>
<link href="css/bootstrap/3.3.7/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap/3.3.7/bootstrap.min.js"></script>
<script src="js/holder.min.js"></script>
</head>
<body>
<!--模态框-->
<div class="container">
<h3 class="page-header">模态框</h3>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!--若上面的button换成a链接<a href="#myModal" class="btn btn-primary btn-lg" data-toggle="modal" >Launch demo modal</a>-->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<!--.modal fade淡入-->
<div class="modal-dialog modal-sm" role="document"><!--.modal-lg|sm对话框大小-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><!--data-dismiss="modal"关闭modal 框-->
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary save">Save changes</button><!--.save点击该按钮后,探出警告框:登录成功,关闭警告框后同时关闭modal框,具体实现见下script-->
</div>
</div>
</div>
</div>
</div>
<!--
模态框基本框架,用js实现模态框
<div class="container">
<h3 class="page-header">模态框</h3>
<button class="btn btn-primary btn-lg smodal" >Launch demo modal
</button>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"></div>
<div class="modal-body"></div>
<div class="modal-footer"></div>
</div>
</div>
</div>
</div>
这段script写在body外面
<script>
//js开启modal
$('.smodal').click(function(){
$('#myModal').modal('show');
})
//模态框出现之后改变body样式
$('#myModal').on('shown.bs.modal',function(e){
$('body').css({'background':'#aaf'});
})
</script>
-->
</body>
<script>
$('.save').click(function(){
alert('登录成功!');
$('#myModal').modal('hide');
})
</script>
</html>
实现效果: