本文為大家分享 Bootstrap Modal 的基本用法,以及如何實現點擊外部時彈窗不消失,供大家參考。
<input id="btntext" type="button" value="添加文本組件" data-toggle="modal" data-target="#myModal" href="../SysManage/ZuJianManage.aspx"/> <!-- Modal --> <div class="modal hide fade" id="myModal" tabindex="-1" role="dialog"> <div class="modal-header"><button class="close" type="button" data-dismiss="modal">×</button> <h3 id="myModalLabel">Modal header</h3> </div> <div class="modal-body"></div> </div>
當然,你也可以用 js 來控制彈窗:
顯示:$('#myModal').modal('show');
隱藏:$('#myModal').modal('hide');
開關:$('#myModal').modal('toggle');
事件:$('#myModal').on('hidden', function () {// do something…});
注意:這裡用到了 href 屬性,這是讓 modal 去 remote 一個 url。當然,你也可以把內容直接寫在 modal-body 裡面。
仔細看 modal 的 div 結構就會明白:modal-body 代表內容,modal-header 是頭部。若要在底部加兩個按鈕,就得用下面的代碼:
<div class="modal-footer"> <a href="#" class="btn">關閉</a> <a href="#" class="btn btn-primary">保存</a> </div>
注意:如果要給 modal 設置寬度,必須加上布局,即把 modal 放在下面的代碼塊中並設置寬度 style="width:500px"。此外,不能直接用 span 樣式塞進 class 裡。
<div class="container"></div>
如果希望彈出框在點擊外部時不消失,只需在觸發模態框的組件上添加 data-backdrop="static" 屬性:
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" data-backdrop="static"> </div>
以上就是本文的全部內容,希望對大家的學習有所幫助。