我正在尝试使用bootstrap模式打开div上的模态。
当我点击div时,屏幕变灰,但模态体不会出现
代码:
<html>
<head>
<title></title>
<link type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet"></link>
<style>
#pageTitle {
display:none;
}
</style>
</head>
<body>
<div class="col-lg-12 text-center">
<h1>Policies</h1>
</div>
<div class="col-lg-12">
<div class="container" id="tiles">
<div class="col-lg-4" style="min-height:80px; background-color:ActiveCaption" id="tileTraffic">
<div class="row">
<div class="col-lg-8">
<h3>Traffic Rules</h3>
</div>
<div class="col-lg-4">
<h1>0</h1>
</div>
</div>
</div>
<div class="col-lg-4" style="min-height:80px; background-color:antiquewhite">
<div class="row">
<div class="col-lg-8">
<h3>Food Policies</h3>
</div>
<div class="col-lg-4">
<h1>0</h1>
</div>
</div>
</div>
<div class="col-lg-4" style="min-height:80px; background-color:cadetblue">
<div class="row">
<div class="col-lg-8">
<h3>Medical Policies</h3>
</div>
<div class="col-lg-4">
<h1>0</h1>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div id="myModalTraffic" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<p>One fine body…</p>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
$("#tileTraffic").click(function () {
$('#myModalTraffic').modal('show');
});
</script>
</body>
</html>
答案 0 :(得分:1)
Bootstrap Modal的结构必须符合Docs,即
<div class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<p>modal body goes here...</p>
</div>
</div>
</div>
</div>
你已经将hide
类应用于模态。删除它,因为它具有样式display: none !important
,导致您的模态不会出现在屏幕上。
答案 1 :(得分:1)
更改
有关
<div id="myModalTraffic" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<p>One fine body…</p>
</div>
</div>
添加这两个div(.modal-dialog和.modal-content)将解决问题
答案 2 :(得分:1)
从您的模式中删除hide
课程,请在实施之前阅读documentation。模态的结构不符合文档。
您的模态应该结构如下:
<div id="myModalTraffic" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<p>One fine body…</p>
</div>
</div>
</div>
</div>
看一下片段:
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-lg-12 text-center">
<h1>Policies</h1>
</div>
<div class="col-lg-12">
<div class="container" id="tiles">
<div class="col-lg-4" style="min-height:80px; background-color:ActiveCaption" id="tileTraffic" data-toggle="modal" data-target="#myModalTraffic">
<div class="row">
<div class="col-lg-8">
<h3>Traffic Rules</h3>
</div>
<div class="col-lg-4">
<h1>0</h1>
</div>
</div>
</div>
<div class="col-lg-4" style="min-height:80px; background-color:antiquewhite">
<div class="row">
<div class="col-lg-8">
<h3>Food Policies</h3>
</div>
<div class="col-lg-4">
<h1>0</h1>
</div>
</div>
</div>
<div class="col-lg-4" style="min-height:80px; background-color:cadetblue">
<div class="row">
<div class="col-lg-8">
<h3>Medical Policies</h3>
</div>
<div class="col-lg-4">
<h1>0</h1>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div id="myModalTraffic" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<p>One fine body…</p>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
&#13;
希望这有帮助!