Bootstrap3 模態(tài)框使用實(shí)例
不支持同時(shí)打開多個(gè)模態(tài)框
務(wù)必盡量將HTML代碼放置在模態(tài)框的body位置以避免其他組件影響模態(tài)框
*autofocus 對(duì)于模態(tài)框無效, 需要自己調(diào)用 $('#myModal').on('shown.bs.modal', function () { $('#myInput').focus() })*
實(shí)例
靜態(tài)
<div class="modal fade" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">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><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
動(dòng)態(tài)
<!-- Button trigger modal --> <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> ... </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>
可選尺寸
<!-- Large modal --> <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button> <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> ... </div> </div> </div> <!-- Small modal --> <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">Small modal</button> <div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel"> <div class="modal-dialog modal-sm" role="document"> <div class="modal-content"> ... </div> </div> </div>
禁用fade
<div class="modal" tabindex="-1" role="dialog" aria-labelledby="..."> ... </div>
使用柵格系統(tǒng)
僅需在body中使用 .rows
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="gridSystemModalLabel">Modal title</h4> </div> <div class="modal-body"> <div class="row"> <div class="col-md-4">.col-md-4</div> <div class="col-md-4 col-md-offset-4">.col-md-4 .col-md-offset-4</div> </div> <div class="row"> <div class="col-md-3 col-md-offset-3">.col-md-3 .col-md-offset-3</div> <div class="col-md-2 col-md-offset-4">.col-md-2 .col-md-offset-4</div> </div> <div class="row"> <div class="col-md-6 col-md-offset-3">.col-md-6 .col-md-offset-3</div> </div> <div class="row"> <div class="col-sm-9"> Level 1: .col-sm-9 <div class="row"> <div class="col-xs-8 col-sm-6"> Level 2: .col-xs-8 .col-sm-6 </div> <div class="col-xs-4 col-sm-6"> Level 2: .col-xs-4 .col-sm-6 </div> </div> </div> </div> </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 -->
使用方法
通過data屬性
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
通過JavaScript調(diào)用
$('#myModal').modal(options)
參數(shù)
名稱 | 類型 | 默認(rèn)值 | 描述 |
---|---|---|---|
backdrop | boolean 或 字符串 ‘static' | true | 設(shè)置為 static 時(shí), 在點(diǎn)擊屏幕時(shí)不會(huì)關(guān)閉 |
keyboard | boolean | true | 鍵盤上的 esc 鍵被按下時(shí)關(guān)閉模態(tài)框 |
show | boolean | true | 模態(tài)框初始化之后就立即顯示出來 |
方法
模態(tài)框激活
.modal(options)
$('#myModal').modal({ keyboard: false })
模態(tài)框觸發(fā)手動(dòng)打開或者關(guān)閉
觸發(fā)在 shown.bs.modal 以及 hidden.bs.modal 事件之前
.modal('toggle')
手動(dòng)打開模態(tài)框
觸發(fā)在 shown.bs.modal 之前
$('#myModal').modal('show')
手動(dòng)隱藏模態(tài)框
觸發(fā)在 hidden.bs.modal 之前
$('#myModal').modal('hide')
事件
按照時(shí)間先后順序分別為 show.bs.modal shown.bs.modal hide.bs.modal hidden.bs.modal
調(diào)用方式
$('#myModal').on('hidden.bs.modal', function (e) { // do something... })
以上所述是小編給大家介紹的Bootstrap3 模態(tài)框使用實(shí)例,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
由 element.appendChild(newNode) ,談開去
由 element.appendChild(newNode) ,談開去...2006-11-11plupload+artdialog實(shí)現(xiàn)多平臺(tái)上傳文件
這篇文章主要介紹了plupload+artdialog實(shí)現(xiàn)多平臺(tái)上傳文件的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07js動(dòng)態(tài)刪除div元素基本思路及實(shí)現(xiàn)代碼
這篇文章主要介紹了js動(dòng)態(tài)刪除div元素基本思路及實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-05-05如何使用webpack打包一個(gè)庫(kù)library的方法步驟
這篇文章主要介紹了如何使用webpack打包一個(gè)庫(kù)library的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12uniapp使用navigateBack方法返回上級(jí)頁面并刷新的簡(jiǎn)單示例
最近寫uniapp項(xiàng)目的時(shí)候發(fā)現(xiàn)有時(shí)候需要更新頁面數(shù)據(jù),所以下面這篇文章主要給大家介紹了關(guān)于uniapp使用navigateBack方法返回上級(jí)頁面并刷新的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03JavaScript焦點(diǎn)事件、鼠標(biāo)事件和滾輪事件使用詳解
這篇文章主要介紹了JavaScript焦點(diǎn)事件、鼠標(biāo)事件和滾輪事件使用詳解,通過示例給大家講解的非常細(xì)致,有需要的小伙伴可以參考下。2016-01-01nullJavascript中創(chuàng)建對(duì)象的五種方法實(shí)例
今天上午,非常郁悶,有很多簡(jiǎn)單基礎(chǔ)的問題搞得我有些迷茫,哎,代碼幾天不寫就忘。目前又不當(dāng)COO,還是得用心記代碼哦!2013-05-05