示例 2 : 点击弹出 示例 3 : 不要动画效果 示例 4 : 点击空白不会收起 示例 5 : 使用JS控制模态窗口 示例 6 : 监听模态的变化
静态模态窗口
<!DOCTYPE html>
<script src="https://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="https://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="https://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">提问</h4>
</div>
<div class="modal-body">
<p>问题描述</p>
<textarea class="form-control"></textarea>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
<button class="btn btn-primary" type="button">提交</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
点击弹出
<!DOCTYPE html>
<script src="https://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="https://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="https://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
提问(点击弹出模态窗口)
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">提问</h4>
</div>
<div class="modal-body">
<p>问题描述</p>
<textarea class="form-control"></textarea>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
<button class="btn btn-primary" type="button">提交</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<div style="height:200px"></div>
不要动画效果
<!DOCTYPE html>
<script src="https://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="https://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="https://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
提问(点击弹出模态窗口)
</button>
<div class="modal " id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">提问</h4>
</div>
<div class="modal-body">
<p>问题描述</p>
<textarea class="form-control"></textarea>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
<button class="btn btn-primary" type="button">提交</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<div style="height:200px"></div>
点击空白不会收起
<!DOCTYPE html>
<script src="https://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="https://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="https://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
提问(点击弹出模态窗口)
</button>
<div class="modal fade" id="myModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">提问</h4>
</div>
<div class="modal-body">
<p>问题描述</p>
<textarea class="form-control"></textarea>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
<button class="btn btn-primary" type="button">提交</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<div style="height:200px"></div>
使用JS控制模态窗口
<!DOCTYPE html>
<script src="https://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="https://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="https://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
<script>
$(function(){
$("#open").click(function(){
$("#myModal").modal('show');
});
$("#submit").click(function(){
alert("信息已经提交");
$("#myModal").modal('hide');
});
$("#toggle").click(function(){
$("#myModal").modal('toggle');
});
});
</script>
<button class="btn btn-default" id="open"> 打开模态窗口</button>
<button class="btn btn-default" id="close"> 关闭模态窗口</button>
<button class="btn btn-default" id="toggle"> 切换模态窗口</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">提问</h4>
</div>
<div class="modal-body">
<p>问题描述</p>
<textarea class="form-control"></textarea>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
<button class="btn btn-primary" id="submit" type="button">提交</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<div style="height:200px"></div>
监听模态的变化
<!DOCTYPE html>
<script src="https://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="https://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="https://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
<script>
$(function(){
$("#myModal").on("show.bs.modal",function(){
alert("开始显示模态窗口");
});
$("#myModal").on("shown.bs.modal",function(){
alert("显示模态窗口完毕");
});
$("#myModal").on("hide.bs.modal",function(){
alert("开始隐藏模态窗口");
});
$("#myModal").on("hidden.bs.modal",function(){
alert("隐藏模态窗口完毕");
});
});
</script>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
提问(点击弹出模态窗口)
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">提问</h4>
</div>
<div class="modal-body">
<p>问题描述</p>
<textarea class="form-control"></textarea>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
<button class="btn btn-primary" type="button">提交</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<div style="height:200px"></div>
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2020-03-17
怎么获取模态窗的文本框输入的值呢
2018-10-12
为什么第一个示例不能关闭
2018-06-13
什么时候来一个模态窗口的CURD就好了~
2018-04-07
这一块儿好难啊
2018-04-01
老师,模态窗口和背景一样了
提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 10 条以前的提问,请 点击查看
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|