---------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">
<title>Navbar Template for Bootstrap</title>
<link rel="stylesheet" href="../../css/bootstrap.min.css" type="text/css"></link>
</head>
<body>
<!--
******************模態(tài)框*************************************************
*
*模態(tài)框以彈出對(duì)話框的形式出現(xiàn)
*
*注意:不支持模態(tài)框重疊,要想同時(shí)支持多個(gè)模態(tài)框,需要自己寫額外的代碼來(lái)實(shí)現(xiàn)。
*
*模態(tài)框的樣式:.modal
*fade:讓模態(tài)框漸入漸出
*
*增強(qiáng)模態(tài)框的可訪問(wèn)性:
*請(qǐng)確保為.modal添加了role="dialog";aria-labelledby="myModalLabel"屬性指
*向模態(tài)框標(biāo)題;aria-hidden="true"告訴輔助性工具略過(guò)模態(tài)框的DOM元素。
*另外,你還應(yīng)該為模態(tài)框添加描述性信息。為.modal添加aria-describedby屬性用以指向描述信息。
*
*通過(guò)data屬性:不需寫JavaScript代碼也可激活模態(tài)框。通過(guò)在一個(gè)起控制器作用的頁(yè)
*面元素(例如,按鈕)上設(shè)置data-toggle="modal",并使用data-target="#foo"或href="#foo"指
*向特定的模態(tài)框即可。
*也可以通通過(guò)JavaScript調(diào)用:只需一行JavaScript代碼,即可通過(guò)id myModal調(diào)用模態(tài)框
*$('#myModal').modal(options)
***************************************************************************
-->
<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">
<!-- 定義模態(tài)框的關(guān)閉按鈕 -->
<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">
<p>One fine body…</p>
</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>
</div>
</div>
<div>
<button id="button1" class="btn btn-default btn-lg" data-toggle="modal" data-target="#myModal">
使用bootstrap的data屬性彈出modal
</button>
</div><br/>
<div>
<button id="button2" class="btn btn-default btn-lg">
使用javascript彈出modal
</button>
</div>
</body>
<script type="text/javascript" src="../../js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
<script>
$(function(){
/*********************************
* $("#myModal").modal({keyboard:true});
* keyboard:true 當(dāng)按下esc鍵退出模態(tài)框有效.
* 為false則無(wú)效,默認(rèn)有效
*/
//$("#myModal").modal({keyboard:true});
/*********************************************
* 給模態(tài)框注冊(cè)一個(gè)事件,""
* hidden.bs.modal和hide.bs.modal在隱藏模態(tài)框時(shí)執(zhí)行
* shown.bs.modal:在show.bs.modal打開(kāi)模態(tài)框時(shí)執(zhí)行
* hidden與hide的區(qū)別是:
* hidden是在模態(tài)框關(guān)閉后執(zhí)行函數(shù)
* hide是在模態(tài)框關(guān)閉之前執(zhí)行函數(shù)
* shown和show的區(qū)別于hidden,hide類似.
*
**********************************************/
$("#myModal").on('hidden.bs.modal', function (e) {
alert(1);
});
$("#myModal").on('hide.bs.modal', function (e) {
alert(2);
});
$("#myModal").on('shown.bs.modal', function (e) {
alert(3);
});
$("#myModal").on('show.bs.modal', function (e) {
alert(4);
});
$("#button2").click(function(){
$("#myModal").modal("toggle");
});
})
</script>
</html>