Bootstrap modal使用及點擊外部不消失的解決方法


這篇文章主要為大家詳細介紹了Bootstrap modal使用及點擊外部不消失的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Bootstrap modal使用及點擊外部不消失的解決方法,供大家參考,具體內容如下

1.代碼:

?
1
2
3
4
5
6
7
8
< 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('toogle');

事件:   $('#myModal').on('hidden', function () {// do something…});

注意:我這邊用到了href屬性,這是讓modal去 remote一個url。當然 ,你可以把你要的內容,直接寫在modal-body里面。

認真看modal的div結構,你就會明白,modal-body是代表內容,modal-header是頭部,那么如果要在底部加兩個按鈕,那么就得用下面的代碼了。

?
1
2
3
4
< div class = "modal-footer" >
< a href = "#" class = "btn" >關閉</ a >
< a href = "#" class = "btn btn-primary" >保存</ a >
</ div >

注意:如果要給modal設置寬度,那必須得加上布局。就是把modal放在下面的代碼塊中,並且設置modal的寬度。style="width:500px".對了,你還不可以用span樣式直接放到class里面。

<div  class="container"></div>

如果要使彈出框點擊外部不消失,在觸發模態框的組件上添加以下屬性 data-backdrop="static"

?
1
2
3
4
5
6
7
8
< div class = "modal hide fade" id = "myModal" tabindex = "-1" role = "dialog"
 
<span style = "font-family: arial, 宋體, sans-serif, tahoma, 'Microsoft YaHei'; font-size: 14px; line-height: 24px;" >
 
< span style = "color:#ff6666;" >data-backdrop="static"</ span >
 
</ span >>
</ div >

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM