<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="http://files.cnblogs.com/rubylouvre/bootstrap.css"/>
<script src="http://files.cnblogs.com/rubylouvre/jquery1.83.js" > </script>
<script src="http://files.cnblogs.com/rubylouvre/bootstrap-transition.js"></script>
<script src="http://files.cnblogs.com/rubylouvre/bootstrap-modal.js"></script>
</head>
<body>
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>弹出层…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
</body>
</html>
代码讲解:
- 使用模态窗口,您需要有某种触发器。您可以使用按钮或链接。这里我们使用的是按钮。
- 如果您仔细查看上面的代码,您会发现在 标签中,data-target=”#myModal” 是您想要在页面上加载的模态框的目标。您可以在页面上创建多个模态框,然后为每个模态框创建不同的触发器。现在,很明显,您不能在同一时间加载多个模块,但您可以在页面上创建多个在不同时间进行加载。
- 在模态框中需要注意两点:
第一是 .modal,用来把的内容识别为模态框。
第二是 .fade class。当模态框被切换时,它会引起内容淡入淡出。 - aria-labelledby=”myModalLabel”,该属性引用模态框的标题。
- 属性 aria-hidden=”true” 用于保持模态窗口不可见,直到触发器被触发为止(比如点击在相关的按钮上)。
-
,modal-header 是为模态窗口的头部定义样式的类。
- class=”close”,close 是一个 CSS class,用于为模态窗口的关闭按钮设置样式。
- data-dismiss=”modal”,是一个自定义的 HTML5 data 属性。在这里它被用于关闭模态窗口。
- class=”modal-footer”,是 Bootstrap CSS 的一个 CSS class,用于为模态窗口的底部设置样式。
- data-toggle=”modal”,HTML5 自定义的 data 属性 data-toggle 用于打开模态窗口。
- -
来源: http://www.runoob.com/bootstrap/bootstrap-modal-plugin.html