本篇文章為大家展示了如何正確的使用Bootstrap3 模態(tài)框,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

不支持同時打開多個模態(tài)框
務必盡量將HTML代碼放置在模態(tài)框的body位置以避免其他組件影響模態(tài)框
*autofocus 對于模態(tài)框無效, 需要自己調(diào)用 $('#myModal').on('shown.bs.modal', function () {
 $('#myInput').focus()
})*實例
靜態(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> <h5 class="modal-title">Modal title</h5> </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 -->
動態(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> <h5 class="modal-title" id="myModalLabel">Modal title</h5> </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> <h5 class="modal-title" id="gridSystemModalLabel">Modal title</h5> </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ù)
| 名稱 | 類型 | 默認值 | 描述 | 
|---|---|---|---|
| backdrop | boolean 或 字符串 ‘static' | true | 設置為 static 時, 在點擊屏幕時不會關閉 | 
| keyboard | boolean | true | 鍵盤上的 esc 鍵被按下時關閉模態(tài)框 | 
| show | boolean | true | 模態(tài)框初始化之后就立即顯示出來 | 
方法
模態(tài)框激活
.modal(options)
$('#myModal').modal({
 keyboard: false
})模態(tài)框觸發(fā)手動打開或者關閉
觸發(fā)在 shown.bs.modal 以及 hidden.bs.modal 事件之前
.modal('toggle')手動打開模態(tài)框
觸發(fā)在 shown.bs.modal 之前
$('#myModal').modal('show')手動隱藏模態(tài)框
觸發(fā)在 hidden.bs.modal 之前
$('#myModal').modal('hide')事件
按照時間先后順序分別為 show.bs.modal shown.bs.modal hide.bs.modal hidden.bs.modal
調(diào)用方式
$('#myModal').on('hidden.bs.modal', function (e) {
 // do something...
})上述內(nèi)容就是如何正確的使用Bootstrap3 模態(tài)框,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創(chuàng)新互聯(lián)網(wǎng)站建設公司行業(yè)資訊頻道。
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)建站www.chinadenli.net,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
                網(wǎng)站題目:如何正確的使用Bootstrap3模態(tài)框-創(chuàng)新互聯(lián)
                
                分享地址:http://www.chinadenli.net/article26/idicg.html
            
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、云服務器、品牌網(wǎng)站建設、虛擬主機、標簽優(yōu)化、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
