您的位置:首页 > Web前端 > BootStrap

Bootstrap学习之模态框

2014-03-03 22:19 281 查看
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link rel="stylesheet" href="css/bootstrap.css">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.js">
</script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.js">
</script>
<script type="text/javaScript">
$(document).ready(function(){
$('#myModal').on('hidden.bs.modal', function (e) {
alert("关闭事件");
})
$('#myModal').on('show.bs.modal', function (e) {
alert("打开对话框之前事情");
})
})
</script>
</head>
<body>
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<button type="button" data-toggle="modal" data-target="#myModal" onclick="openSelectDialog()">
按住button启动对话框
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria- hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
aaaaaaaaaaaaa
</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 changes
</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</body>
</html>

不需写JavaScript代码也可激活模态框。通过在一个起控制器作用的页面元素(例如,按钮)上设置
data-toggle="modal"
,并使用
data-target="#foo"
href="#foo"
指向特定的模态框即可

事件

Bootstrap的模态框类暴露了一些事件用于截获并执行自己的代码。

事件类型描述
show.bs.modalThis event fires immediately when the 
show
 instance method is called.
If caused by a click, the clicked element is available as the 
relatedTarget
 property
of the event.
shown.bs.modalThis event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the 
relatedTarget
 property
of the event.
hide.bs.modalThis event is fired immediately when the 
hide
 instance method has been
called.
hidden.bs.modalThis event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript 对话框