Make use of Bootstrap's modal more monkey-friendly.


参考地址:http://nakupanda.github.io/bootstrap3-dialog/

模态弹框:

<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</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 -->
Dialog弹出层:
        BootstrapDialog.alert('I want banana!');
 

Examples


Simplest

 

只提供信息显示,并保持所有其他事情默认。

        BootstrapDialog.show({
message: 'Hi Apple!'
});

Dialog Title


        BootstrapDialog.show({
title: 'Say-hello dialog',
message: 'Hi Apple!'
});
 

操作对话标题


        BootstrapDialog.show({
title: 'Default Title',
message: 'Click buttons below.',
buttons: [{
label: 'Title 1',
action: function(dialog) {
dialog.setTitle('Title 1');
}
}, {
label: 'Title 2',
action: function(dialog) {
dialog.setTitle('Title 2');
}
}]
});
 

操作对话信息


        BootstrapDialog.show({
title: 'Default Title',
message: 'Click buttons below.',
buttons: [{
label: 'Message 1',
action: function(dialog) {
dialog.setMessage('Message 1');
}
}, {
label: 'Message 2',
action: function(dialog) {
dialog.setMessage('Message 2');
}
}]
});
 

加载远程页面(1)

        BootstrapDialog.show({
message: $('<div></div>').load('remote.html')
});

加载远程页面 (2)

        BootstrapDialog.show({
message: function(dialog) {
var $message = $('<div></div>');
var pageToLoad = dialog.getData('pageToLoad');
$message.load(pageToLoad); return $message;
},
data: {
'pageToLoad': 'remote.html'
}
});
 

Buttons

        BootstrapDialog.show({
message: 'Hi Apple!',
buttons: [{
label: 'Button 1'
}, {
label: 'Button 2',
cssClass: 'btn-primary',
action: function(){
alert('Hi Orange!');
}
}, {
icon: 'glyphicon glyphicon-ban-circle',
label: 'Button 3',
cssClass: 'btn-warning'
}, {
label: 'Close',
action: function(dialogItself){
dialogItself.close();
}
}]
});
 

操作Buttons

通过bootstrapdialog创建按钮有一些额外的功能:
$button.toggleEnable(true|false);
$button.enable(); // 相当于 $button.toggleEnable(true);
$button.disable(); // 相当于  $button.toggleEnable(false);
$button.toggleSpin(true|false);
$button.spin(); // 相当于 $button.toggleSpin(true);
$button.stopSpin(); // 相当于  $button.toggleSpin(false);

        BootstrapDialog.show({
title: 'Manipulating Buttons',
message: function(dialog) {
var $content = $('<div><button class="btn btn-success">Revert button status right now.</button></div>');
var $footerButton = dialog.getButton('btn-1');
$content.find('button').click({$footerButton: $footerButton}, function(event) {
event.data.$footerButton.enable();
event.data.$footerButton.stopSpin();
dialog.setClosable(true);
}); return $content;
},
buttons: [{
id: 'btn-1',
label: 'Click to disable and spin.',
action: function(dialog) {
var $button = this; // 'this' here is a jQuery object that wrapping the <button> DOM element.
$button.disable();
$button.spin();
dialog.setClosable(false);
}
}]
});
 

按钮的热键

试着按下面的按钮。
最后一个按钮被禁用,所以没有事情发生,当按下热键。
请注意,如果您的对话框中有一些需要键盘操作的组件,可能会出现冲突,您可以尝试下一个示例。

        BootstrapDialog.show({
title: 'Button Hotkey',
message: 'Try to press some keys...',
onshow: function(dialog) {
dialog.getButton('button-c').disable();
},
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.');
}
}]
});
 

创建 dialog 实例

BootstrapDialog.show(...) 只是一个快捷方式,如果你需要对话框实例,用“新”。


        // Using init options
var dialogInstance1 = new BootstrapDialog({
title: 'Dialog instance 1',
message: 'Hi Apple!'
});
dialogInstance1.open(); // Construct by using setters
var dialogInstance2 = new BootstrapDialog();
dialogInstance2.setTitle('Dialog instance 2');
dialogInstance2.setMessage('Hi Orange!');
dialogInstance2.setType(BootstrapDialog.TYPE_SUCCESS);
dialogInstance2.open(); // Using chain callings
var dialogInstance3 = new BootstrapDialog()
.setTitle('Dialog instance 3')
.setMessage('Hi Everybody!')
.setType(BootstrapDialog.TYPE_INFO)
.open();
 

事实上BootstrapDialog.show(...) 也将返回创建的对话框实例。


        // You can use dialogInstance later.
var dialogInstance = BootstrapDialog.show({
message: 'Hello Banana!'
});

Button with identifier


        var dialog = new BootstrapDialog({
message: 'Hi Apple!',
buttons: [{
id: 'btn-1',
label: 'Button 1'
}]
});
dialog.realize();
var btn1 = dialog.getButton('btn-1');
btn1.click({'name': 'Apple'}, function(event){
alert('Hi, ' + event.data.name);
});
dialog.open();
 

较大的对话框

默认情况下,对话框的大小是 'size-normal' 或 BootstrapDialog.SIZE_NORMAL, 但你可以通过设置选项的 'size' 的'size-large' 或BootstrapDialog.SIZE_LARGE.


        BootstrapDialog.show({
size: BootstrapDialog.SIZE_LARGE,
message: 'Hi Apple!',
buttons: [{
label: 'Button 1'
}, {
label: 'Button 2',
cssClass: 'btn-primary',
action: function(){
alert('Hi Orange!');
}
}, {
icon: 'glyphicon glyphicon-ban-circle',
label: 'Button 3',
cssClass: 'btn-warning'
}, {
label: 'Close',
action: function(dialogItself){
dialogItself.close();
}
}]
});
 

More dialog sizes

Please note that specifying BootstrapDialog.SIZE_WIDE is equal to using css class 'modal-lg' on Bootstrap Modal.


        BootstrapDialog.show({
title: 'More dialog sizes',
message: 'Hi Apple!',
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);
}
}]
});
 

更多信息

bootstrapdialog支持显示丰富的内容,所以你甚至可以使用一个视频剪辑你的对话框中的消息。

        var $textAndPic = $('<div></div>');
$textAndPic.append('Who\'s this? <br />');
$textAndPic.append('<img src="./images/pig.ico" />'); BootstrapDialog.show({
title: 'Guess who that is',
message: $textAndPic,
buttons: [{
label: 'Acky',
action: function(dialogRef){
dialogRef.close();
}
}, {
label: 'Robert',
action: function(dialogRef){
dialogRef.close();
}
}]
});
 

Dialog closable / unclosable

If option 'closable' is set to false, the default closing behaviors will be disabled, but you can still close the dialog by using dialog.close().


        BootstrapDialog.show({
message: 'Hi Apple!',
closable: false,
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();
}
}]
});
 

关闭对话框的更多控件

 

默认情况下,当选择 'closable' 设置为true,对话框可以通过这些方式关闭:点击在对话框中,按ESC键,点击对话框标题右侧的关闭图标。

如果你想让你的对话框关闭时,对话框标题的关闭图标被点击,可以设置的选项 'closeByBackdrop' and 'closeByKeyboard' 为 false.


        BootstrapDialog.show({
message: 'Hi Apple!',
message: 'You can not close this dialog by clicking outside and pressing ESC key.',
closable: true,
closeByBackdrop: false,
closeByKeyboard: false,
buttons: [{
label: 'Close the dialog',
action: function(dialogRef){
dialogRef.close();
}
}]
});

Confirm

  BootstrapDialog.confirm('Hi Apple, are you sure?');

Confirm with callback

        BootstrapDialog.confirm('Hi Apple, are you sure?', function(result){
if(result) {
alert('Yup.');
}else {
alert('Nope.');
}
});

Available options


Please note that all options described below are optional, but you will have a weird dialog if you don't even give it a message to display.
Most options can be set via init options or property setters.

Option Possible values Description
type BootstrapDialog.TYPE_DEFAULT or 'type-default'
BootstrapDialog.TYPE_INFO or 'type-info'
BootstrapDialog.TYPE_PRIMARY or 'type-primary' (default)
BootstrapDialog.TYPE_SUCCESS or 'type-success'
BootstrapDialog.TYPE_WARNING or 'type-warning'
BootstrapDialog.TYPE_DANGER or 'type-danger'
Give your dialog a specific look, color scheme can be seen on Bootstrap's Button.
size BootstrapDialog.SIZE_NORMAL or 'size-normal' (default)
BootstrapDialog.SIZE_WIDE or 'size-wide'
BootstrapDialog.SIZE_LARGE or 'size-large'
-
cssClass - Additional css classes that will be added to your dialog.
title String or Object(html) -
message String or Object(html) -
buttons array Examples:

BootstrapDialog.show({
title: 'Say-hello dialog',
message: 'Hello world!',
buttons: [{
id: 'btn-ok',
icon: 'glyphicon glyphicon-check',
label: 'OK',
cssClass: 'btn-primary',
autospin: false,
action: function(dialogRef){
dialogRef.close();
}
}]
});
 

id: optional, if id is set, you can use dialogInstance.getButton(id) to get the button later.
icon: optional, if set, the specified icon will be added to the button.
cssClass: optional, additional css class to be added to the button.
autospin: optinal, if it's true, after clicked the button a spinning icon appears.
action: optional, if provided, the callback will be invoked after the button is clicked, and the dialog instance will be passed to the callback function.

closable true | false When set to true, you can close the dialog by:

  • Clicking the close icon in dialog header.
  • Clicking outside the dialog.
  • ESC key.
spinicon Icon class name, for example 'glyphicon glyphicon-check'.
Default value is 'glyphicon glyphicon-asterisk'.
Specify what icon to be used as the spinning icon when button's 'autospin' is set to true.
data Key-value object. For example {'id' : '100'} Data to be bound to the dialog.
onshow function If provided, it will be invoked when the dialog is popping up.
onshown function If provided, it will be invoked when the dialog is popped up.
onhide function If provided, it will be invoked when the dialog is popping down.
onhidden function If provided, it will be invoked when the dialog is popped down.
autodestroy true (default) | false When it's true, all modal stuff will be removed from the DOM tree after the dialog is popped down, set it to false if you need your dialog (same instance) pups up and down again and again.
description String If provided, 'aria-describedby' attribute will be added to the dialog with the description string as its value. This can improve accessibility, as the description can be read by screen readers.
nl2br true | false Automatically convert line breaking character to <br /> if it's set to true, everything keeps original if it's false.

Available methods


Method Description
open() Open the dialog. Usage: dialogInstance.open()
close() Close the dialog. Usage: dialogInstance.close()
getModal() Return the raw modal, equivalent to $('<div class='modal fade'...></div>')
getModalDialog() Return the raw modal dialog.
getModalContent() Return the raw modal content.
getModalHeader() Return the raw modal header.
getModalBody() Return the raw modal body.
getModalFooter() Return the raw modal footer.
getData(key) Get data entry according to the given key, returns null if no data entry found.
setData(key, value) Bind data entry to dialog instance, value can be any types that javascript supports.
enableButtons(boolean) Disable all buttons in dialog footer when it's false, enable all when it's true.
setClosable(boolean) When set to true (default), dialog can be closed by clicking close icon in dialog header, or by clicking outside the dialog, or, ESC key is pressed.
realize() Calling dialog.open() will automatically get this method called first, but if you want to do something on your dialog before it's shown, you can manually call dialog.realize() before calling dialog.open().

Go to the project. | Contact me if you can help to improve this example page.

Bootstrap之BootstrapDialog的更多相关文章

  1. bootstrap dialog对话框,完成操作提示框

    1. 依赖文件: bootstrap.js bootstrap-dialog.js bootstrap.css bootstrap-dialog.css 2.代码 BootstrapDialog.co ...

  2. BootstrapDialog.confirm确认对话框

    1. 依赖文件: bootstrap.js bootstrap-dialog.js bootstrap.css bootstrap-dialog.css 2.代码 BootstrapDialog.co ...

  3. 公共文件模块include

    首先新建一个include 把所有引入的文件放入公共文件里 function getBaseURL() { var pathName = window.document.location.pathna ...

  4. Bootstrap-dialog的使用(续Bootstrap Table)

    Bootstrap-dialog实现表格内容的增,删,改. 插件引入:必须先引入jquery和bootstrap和artTemplate. <link rel="stylesheet& ...

  5. 基于Bootstrap的对话框插件bootstrap-dialog

    写在前面: bootstrap本身提供了它自己的模态框,但是感觉并不太友好,当需要在页面点击一个按钮打开一个窗口页面时,使用原有的bootstrap的模态框,会把所有的代码全部写在一个jsp页面,显得 ...

  6. bootstrapDialog插件集成datatables插件遇到的异常

    最近项目中,涉及到很多细分领域的东西,有好些目前还没有详细的方案.这是后话,当前起步阶段,我要把握技术路线,搭建基础架构!其中,有好几个地方都用到模态框(Modal), 虽然Bootstrap框架里面 ...

  7. bootstrap中弹出窗体dialog的自定义

    感谢nakupanda的https://github.com/nakupanda/bootstrap3-dialog 根据需要弹出窗体,但是可以移动,不遮挡下面的内容,所以就修改了源代码,添加了一个属 ...

  8. BootstrapDialog.show函数底层简化

    平台用的全部都是BootStrapDialog的弹窗,然后美工设计了一个统一的样式,每次写的时候,都要对其进行样式重写:写吐了快,所以对BootStrap.底层做了修改: 也就是说,只要你要写的界面包 ...

  9. select option 下拉多选单选bootstrap插件使用总结2

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. NET中的规范标准注释(一) -- XML注释标签讲解

    一.摘要 .Net允许开发人员在源代码中插入XML注释,这在多人协作开发的时候显得特别有用. C#解析器可以把代码文件中的这些XML标记提取出来,并作进一步的处理为外部文档. 这篇文章将展示如何使用这 ...

  2. jquery统计页面的pv/ip及停留时间等

    我们在做网站的时候经常需要统计网站的访问信息,这里介绍一个用jquery写的一个统计方法 新建一个js文件jun_record.js 代码如下: var start; var end; var tim ...

  3. ProcExp和TaskMgr的列对比

    这两者的大部分列都是一致的,包括pid.threads.handles等,但在内存方面却有出入,对比如下: ProcExp TaskMgr Sample.exe Private Delta Bytes ...

  4. CSS强制中英文换行与不换行

    1. word-break:break-all; 只对英文起作用,以字母作为换行依据 2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 3. white-space ...

  5. git常用命令有用

    http://www.cnblogs.com/cspku/articles/Git_cmds.html

  6. <input type="file">中怎设置那个按钮的样式

    最近才开始学习HTML,在练习表单的过程中,发现在使用<input type="file"/>这个类型的元素,产生的文件框和浏览按扭,它们的样式往往不符合我们的需要.怎 ...

  7. android 拉伸图片

    Android拉伸图片用的是9.png格式的图片,这种图片可以指定图片的那一部分拉伸,那一部分显示内容,美工给的小图片也能有很好的显示效果. 原背景图片 可以看到原背景图片很小,即使在再长的文字,背景 ...

  8. ACM 杂题,思路题 整理

    UVa 11572 - Unique Snowflakes 问一个数组中,无重复数字的最长子串长度是多少. 用map维护某数字上次出现的位置.另外用变量last表示上次出现数字重复的位置. 如果出现重 ...

  9. 【转载】【Windows批处理IV】批量进行文件重命名

    1.过滤文件名中所有数字.汉字.特殊字符(含空格) @echo off for %%a in (*.*) do ( if "%%~nxa" neq "%~nx0" ...

  10. 黑马程序员:Java编程_面向对象

    =========== ASP.Net+Android+IOS开发..Net培训.期待与您交流!=========== 面向对象和面向过程都是一种思想,面向过程强调的是功能行为,面向对象是将功能封装进 ...