Bootstrap BootstrapDialog使用詳解
這里有兩種展現(xiàn)方式
寫(xiě)在前面:首先你要引入的庫(kù)有
css : bootstrap.min.css bootstrap-dialog.css
js : jquery-1.11.1.min.js bootstrap.min.js bootstrap-dialog.js
1、通過(guò)html代碼顯示
<!-- Button trigger modal 彈出框的觸發(fā)器 -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal 彈出框的結(jié)構(gòu) -->
<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>
這種方式簡(jiǎn)單直觀; 但會(huì)增加html的‘重量',而且不夠靈活,大量使用時(shí)不建議使用
2、通過(guò)js的方式展現(xiàn)(需要注意的地方我都寫(xiě)在注釋里了)
(1)最簡(jiǎn)單的實(shí)現(xiàn)方式:
BootstrapDialog.show({
message: 'Hi Apple!'
});
還有一種更簡(jiǎn)單的實(shí)現(xiàn)方式:BootstrapDialog.alert('I want banana!'); //異步加載 適合用在方法的最后
(2)buttons
BootstrapDialog.show({
message : "message",
buttons : [{
label : "btn1",
cssClass : "btn-primary" //給按鈕添加類(lèi)名 可以通過(guò)此方式給按鈕添加樣式
},{
label : "btn2",
icon : "glyphicon glyphicon-ban-circle" //通過(guò)bootstrap的樣式添加圖標(biāo)按鈕
},{
label : "btn3",
action : function(dialog){ //給當(dāng)前按鈕添加點(diǎn)擊事件
dialog.close();
}
}
]
});
(3)操作title、message 可以通過(guò) setTitle 和 setMessage 操作title和message
BootstrapDialog.show({
title : "this is a title!", //title
message : "Document Comtent",
buttons : [{
label : "cancel",
action : function(dialog){
dialog.setTitle("title2"); //操作title
dialog.setMessage("message1"); //操作message
dialog.close();
}
},{
label : "Ok",
action : function(dialog){
dialog.close();
}
}]
})
(4)按鈕熱鍵 (本人認(rèn)為不常用)
BootstrapDialog.show({
title: 'Button Hotkey',
message: 'Try to press some keys...',
onshow: function(dialog) {
dialog.getButton('button-c').disable(); //通過(guò)getButton('id')獲得按鈕
},
buttons: [{
label: '(A) Button A',
hotkey: 65, // Keycode of keyup event of key 'A' is 65.
action: function() {
alert('Finally, you loved Button A.');
}
}, {
label: '(B) Button B',
hotkey: 66,
action: function() {
alert('Hello, this is Button B!');
}
}, {
id: 'button-c',
label: '(C) Button C',
hotkey: 67,
action: function(){
alert('This is Button C but you won\'t see me dance.');
}
}]
})
(5)動(dòng)態(tài)加載message
BootstrapDialog.show({
//message : $("<div></div>").load('content.html') //第一種方式
message : function(content){ //第二種方式
var $message = $("<div></div>");
var loadData = content.getData("contentFile");
$message.load(loadData);
return $message; //一定記得返回值!
},
data : {"contentFile" :"content.html"}
});
(6)控制彈出框右上角的關(guān)閉按鈕
BootstrapDialog.show({
message: 'Hi Apple!',
closable: true, //控制彈出框拉右上角是否顯示 ‘x' 默認(rèn)為true
buttons: [{
label: 'Dialog CLOSABLE!',
cssClass: 'btn-success',
action: function(dialogRef){
dialogRef.setClosable(true);
}
}, {
label: 'Dialog UNCLOSABLE!',
cssClass: 'btn-warning',
action: function(dialogRef){
dialogRef.setClosable(false);
}
}, {
label: 'Close the dialog',
action: function(dialogRef){
dialogRef.close(); //總是能關(guān)閉彈出框
}
}]
});
(7) 彈出框的尺寸
BootstrapDialog.show({
title: 'More dialog sizes',
message: 'Hi Apple!',
size : BootstrapDialog.SIZE_NORMAL //默認(rèn)尺寸
buttons: [{
label: 'Normal',
action: function(dialog){
dialog.setTitle('Normal');
dialog.setSize(BootstrapDialog.SIZE_NORMAL);
}
}, {
label: 'Small',
action: function(dialog){
dialog.setTitle('Small');
dialog.setSize(BootstrapDialog.SIZE_SMALL);
}
}, {
label: 'Wide',
action: function(dialog){
dialog.setTitle('Wide');
dialog.setSize(BootstrapDialog.SIZE_WIDE);
}
}, {
label: 'Large',
action: function(dialog){
dialog.setTitle('Large');
dialog.setSize(BootstrapDialog.SIZE_LARGE);
}
}]
});
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 頁(yè)面遮罩層,并且阻止頁(yè)面body滾動(dòng)。bootstrap模態(tài)框原理
- Bootstrap每天必學(xué)之模態(tài)框(Modal)插件
- Bootstrap模態(tài)框(modal)垂直居中的實(shí)例代碼
- 淺析BootStrap中Modal(模態(tài)框)使用心得
- bootstrap模態(tài)框消失問(wèn)題的解決方法
- Bootstrap模態(tài)框禁用空白處點(diǎn)擊關(guān)閉
- BOOTSTRAP時(shí)間控件顯示在模態(tài)框下面的bug修復(fù)
- Bootstrap模態(tài)框調(diào)用功能實(shí)現(xiàn)方法
- BootStrap+Angularjs+NgDialog實(shí)現(xiàn)模式對(duì)話(huà)框
- bootstrap3-dialog-master模態(tài)框使用詳解
相關(guān)文章
一文熟練掌握J(rèn)avaScript中Object.keys()與Object.values()的實(shí)用技巧
本文詳細(xì)介紹了JavaScript中Object.keys()和Object.values()方法的使用方法、功能及應(yīng)用場(chǎng)景,通過(guò)實(shí)例展示了如何使用這些方法進(jìn)行對(duì)象的遍歷、復(fù)制、比較和屬性計(jì)算等操作,需要的朋友可以參考下2025-01-01
微信小程序利用云函數(shù)獲取手機(jī)號(hào)碼
這篇文章主要介紹了微信小程序利用云函數(shù)獲取手機(jī)號(hào)碼功能,本文通過(guò)實(shí)例代碼給大家講解的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
JavaScript Event事件學(xué)習(xí)第一章 Event介紹
Events是每一個(gè)JavaScript程序核心。什么是事件處理,它有什么問(wèn)題和怎樣寫(xiě)出跨瀏覽器的代碼,我將在這一章做一個(gè)概述。我也會(huì)提供一些有精彩的關(guān)于事件處理程序的細(xì)節(jié)的文章。2010-02-02
詳解JavaScript如何實(shí)現(xiàn)四種常用排序
這篇文章主要為大家介紹了如何利用JavaScript實(shí)現(xiàn)四個(gè)常用的排序:插入排序、交換排序、選擇排序和歸并排序,文中利用動(dòng)圖詳細(xì)介紹了實(shí)現(xiàn)過(guò)程,需要的可以參考一下2022-02-02
JS+CSS實(shí)現(xiàn)自動(dòng)切換的網(wǎng)頁(yè)滑動(dòng)門(mén)菜單效果代碼
這篇文章主要介紹了JS+CSS實(shí)現(xiàn)自動(dòng)切換的網(wǎng)頁(yè)滑動(dòng)門(mén)菜單效果代碼,涉及JavaScript基于時(shí)間函數(shù)動(dòng)態(tài)變換頁(yè)面tab樣式的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
如何通過(guò)JavaScript來(lái)實(shí)現(xiàn)頁(yè)面間數(shù)據(jù)傳遞
這篇文章主要給大家介紹了關(guān)于如何通過(guò)JavaScript來(lái)實(shí)現(xiàn)頁(yè)面間數(shù)據(jù)傳遞的相關(guān)資料,在前端開(kāi)發(fā)中我們常常需要從一個(gè)跳到另一個(gè)頁(yè)面,并且將當(dāng)前頁(yè)面的數(shù)據(jù)傳遞過(guò)去,需要的朋友可以參考下2023-11-11
在標(biāo)題欄顯示新消息提示,很多公司項(xiàng)目中用到這個(gè)方法
在標(biāo)題欄顯示新消息提示,很多公司項(xiàng)目中用到這個(gè)方法,需要的朋友可以參考下。2011-11-11

