class="mod_bootstrapdialog.show">
当前位置:   article > 正文

bootstrap3-dialog使用实例_bootstrapdialog.show

bootstrapdialog.show

转载自:http://nakupanda.github.io/bootstrap3-dialog/

Monkeys love the Modal Dialog from Bootstrap, but they're getting angry because they have to write this stuff:

<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 -->

What they want is more like this:

  1. BootstrapDialog.alert('I want banana!');

Like it? See Available Options or try more Examples below.

Examples


Simplest

Provide only the message to show, and keep all other things default.

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

Dialog Title

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

Manipulating Dialog Title

  1. BootstrapDialog.show({
  2. title: 'Default Title',
  3. message: 'Click buttons below.',
  4. buttons: [{
  5. label: 'Title 1',
  6. action: function(dialog) {
  7. dialog.setTitle('Title 1');
  8. }
  9. }, {
  10. label: 'Title 2',
  11. action: function(dialog) {
  12. dialog.setTitle('Title 2');
  13. }
  14. }]
  15. });

Manipulating Dialog Message

  1. BootstrapDialog.show({
  2. title: 'Default Title',
  3. message: 'Click buttons below.',
  4. buttons: [{
  5. label: 'Message 1',
  6. action: function(dialog) {
  7. dialog.setMessage('Message 1');
  8. }
  9. }, {
  10. label: 'Message 2',
  11. action: function(dialog) {
  12. dialog.setMessage('Message 2');
  13. }
  14. }]
  15. });

Loading remote page (1)

There are some workarounds for loading remote page into BootstrapDialog as message, one of those workarounds is as below. 
Check out the remote.html.

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

Loading remote page (2)

Another solution of loading remote page into BootstrapDialog. 
This one is more flexible and customizable, but it's also a bit more complicated to use.

  1. BootstrapDialog.show({
  2. message: function(dialog) {
  3. var $message = $('<div></div>');
  4. var pageToLoad = dialog.getData('pageToLoad');
  5. $message.load(pageToLoad);
  6. return $message;
  7. },
  8. data: {
  9. 'pageToLoad': 'remote.html'
  10. }
  11. });

Buttons

  1. BootstrapDialog.show({
  2. message: 'Hi Apple!',
  3. buttons: [{
  4. label: 'Button 1'
  5. }, {
  6. label: 'Button 2',
  7. cssClass: 'btn-primary',
  8. action: function(){
  9. alert('Hi Orange!');
  10. }
  11. }, {
  12. icon: 'glyphicon glyphicon-ban-circle',
  13. label: 'Button 3',
  14. cssClass: 'btn-warning'
  15. }, {
  16. label: 'Close',
  17. action: function(dialogItself){
  18. dialogItself.close();
  19. }
  20. }]
  21. });

Manipulating Buttons

Buttons that created by BootstrapDialog have some extra functions available: 
$button.toggleEnable(true|false); 
$button.enable(); // Equals to $button.toggleEnable(true); 
$button.disable(); // Equals to $button.toggleEnable(false); 
$button.toggleSpin(true|false); 
$button.spin(); // Equals to $button.toggleSpin(true);
$button.stopSpin(); // Equals to $button.toggleSpin(false);

  1. BootstrapDialog.show({
  2. title: 'Manipulating Buttons',
  3. message: function(dialog) {
  4. var $content = $('<div><button class="btn btn-success">Revert button status right now.</button></div>');
  5. var $footerButton = dialog.getButton('btn-1');
  6. $content.find('button').click({$footerButton: $footerButton}, function(event) {
  7. event.data.$footerButton.enable();
  8. event.data.$footerButton.stopSpin();
  9. dialog.setClosable(true);
  10. });
  11. return $content;
  12. },
  13. buttons: [{
  14. id: 'btn-1',
  15. label: 'Click to disable and spin.',
  16. action: function(dialog) {
  17. var $button = this; // 'this' here is a jQuery object that wrapping the <button> DOM element.
  18. $button.disable();
  19. $button.spin();
  20. dialog.setClosable(false);
  21. }
  22. }]
  23. });

Button Hotkey

Try to press the keys that have been associated with buttons below. 
The last button is disabled so nothing is going to happen when pressing its hotkey. 
Please note that if there are some components that require keyboard operations in your dialog, conflicts may occur, you can try next example.

  1. BootstrapDialog.show({
  2. title: 'Button Hotkey',
  3. message: 'Try to press some keys...',
  4. onshow: function(dialog) {
  5. dialog.getButton('button-c').disable();
  6. },
  7. buttons: [{
  8. label: '(A) Button A',
  9. hotkey: 65, // Keycode of keyup event of key 'A' is 65.
  10. action: function() {
  11. alert('Finally, you loved Button A.');
  12. }
  13. }, {
  14. label: '(B) Button B',
  15. hotkey: 66,
  16. action: function() {
  17. alert('Hello, this is Button B!');
  18. }
  19. }, {
  20. id: 'button-c',
  21. label: '(C) Button C',
  22. hotkey: 67,
  23. action: function(){
  24. alert('This is Button C but you won\'t see me dance.');
  25. }
  26. }]
  27. });

Keys Conflicts

Try to avoid doing similar in your code.

  1. BootstrapDialog.show({
  2. title: 'Button Hotkey',
  3. message: $('<textarea class="form-control" placeholder="Try to input multiple lines here..."></textarea>'),
  4. buttons: [{
  5. label: '(Enter) Button A',
  6. cssClass: 'btn-primary',
  7. hotkey: 13, // Enter.
  8. action: function() {
  9. alert('You pressed Enter.');
  10. }
  11. }]
  12. });

Opening multiple dialogs

A good looking stacked dialogs. Please also note the second and the third dialog are draggable.

  1. var shortContent = '<p>Something here.</p>';
  2. var longContent = '';
  3. for(var i = 1; i <= 200; i++) {
  4. longContent += shortContent;
  5. }
  6. BootstrapDialog.show({
  7. title: 'Another long dialog',
  8. message: longContent
  9. });
  10. BootstrapDialog.show({
  11. title: 'Another short dialog',
  12. message: shortContent,
  13. draggable: true
  14. });
  15. BootstrapDialog.show({
  16. title: 'A long dialog',
  17. message: longContent,
  18. draggable: true
  19. });
  20. BootstrapDialog.show({
  21. title: 'A short dialog',
  22. message: shortContent
  23. });

Creating dialog instances

BootstrapDialog.show(...) is just a shortcut method, if you need dialog instances, use 'new'.

  1. // Using init options
  2. var dialogInstance1 = new BootstrapDialog({
  3. title: 'Dialog instance 1',
  4. message: 'Hi Apple!'
  5. });
  6. dialogInstance1.open();
  7. // Construct by using setters
  8. var dialogInstance2 = new BootstrapDialog();
  9. dialogInstance2.setTitle('Dialog instance 2');
  10. dialogInstance2.setMessage('Hi Orange!');
  11. dialogInstance2.setType(BootstrapDialog.TYPE_SUCCESS);
  12. dialogInstance2.open();
  13. // Using chain callings
  14. var dialogInstance3 = new BootstrapDialog()
  15. .setTitle('Dialog instance 3')
  16. .setMessage('Hi Everybody!')
  17. .setType(BootstrapDialog.TYPE_INFO)
  18. .open();

In fact BootstrapDialog.show(...) will also return the created dialog instance.

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

Open / Close multiple dialogs

This example demonstrates opening and closing a batch of dialogs at one time. 
Dialog that created by BootstrapDialog will be in a container BootstrapDialog.dialogs before it's closed and destroyed, iterate BootstrapDialog.dialogs to find all dialogs that havn't been destroyed.

  1. var howManyDialogs = 5;
  2. for(var i = 1; i <= howManyDialogs; i++) {
  3. var dialog = new BootstrapDialog({
  4. title: 'Dialog No.' + i,
  5. message: 'Hello Houston, this is dialog No.' + i,
  6. buttons: [{
  7. label: 'Close this dialog.',
  8. action: function(dialogRef){
  9. dialogRef.close();
  10. }
  11. }, {
  12. label: 'Close ALL opened dialogs',
  13. cssClass: 'btn-warning',
  14. action: function(){
  15. // You can also use BootstrapDialog.closeAll() to close all dialogs.
  16. $.each(BootstrapDialog.dialogs, function(id, dialog){
  17. dialog.close();
  18. });
  19. }
  20. }]
  21. });
  22. dialog.open();
  23. }

Button with identifier

  1. var dialog = new BootstrapDialog({
  2. message: 'Hi Apple!',
  3. buttons: [{
  4. id: 'btn-1',
  5. label: 'Button 1'
  6. }]
  7. });
  8. dialog.realize();
  9. var btn1 = dialog.getButton('btn-1');
  10. btn1.click({'name': 'Apple'}, function(event){
  11. alert('Hi, ' + event.data.name);
  12. });
  13. dialog.open();

Message types

  1. var types = [BootstrapDialog.TYPE_DEFAULT,
  2. BootstrapDialog.TYPE_INFO,
  3. BootstrapDialog.TYPE_PRIMARY,
  4. BootstrapDialog.TYPE_SUCCESS,
  5. BootstrapDialog.TYPE_WARNING,
  6. BootstrapDialog.TYPE_DANGER];
  7. $.each(types, function(index, type){
  8. BootstrapDialog.show({
  9. type: type,
  10. title: 'Message type: ' + type,
  11. message: 'What to do next?',
  12. buttons: [{
  13. label: 'I do nothing.'
  14. }]
  15. });
  16. });

Changing dialog type

  1. var types = [BootstrapDialog.TYPE_DEFAULT,
  2. BootstrapDialog.TYPE_INFO,
  3. BootstrapDialog.TYPE_PRIMARY,
  4. BootstrapDialog.TYPE_SUCCESS,
  5. BootstrapDialog.TYPE_WARNING,
  6. BootstrapDialog.TYPE_DANGER];
  7. var buttons = [];
  8. $.each(types, function(index, type) {
  9. buttons.push({
  10. label: type,
  11. cssClass: 'btn-default btn-sm',
  12. action: function(dialog) {
  13. dialog.setType(type);
  14. }
  15. });
  16. });
  17. BootstrapDialog.show({
  18. title: 'Changing dialog type',
  19. message: 'Click buttons below...',
  20. buttons: buttons
  21. });

Larger dialog

By default, the dialog size is 'size-normal' or BootstrapDialog.SIZE_NORMAL, but you can have a larger dialog by setting option 'size' to 'size-large' or BootstrapDialog.SIZE_LARGE.

  1. BootstrapDialog.show({
  2. size: BootstrapDialog.SIZE_LARGE,
  3. message: 'Hi Apple!',
  4. buttons: [{
  5. label: 'Button 1'
  6. }, {
  7. label: 'Button 2',
  8. cssClass: 'btn-primary',
  9. action: function(){
  10. alert('Hi Orange!');
  11. }
  12. }, {
  13. icon: 'glyphicon glyphicon-ban-circle',
  14. label: 'Button 3',
  15. cssClass: 'btn-warning'
  16. }, {
  17. label: 'Close',
  18. action: function(dialogItself){
  19. dialogItself.close();
  20. }
  21. }]
  22. });

More dialog sizes

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

  1. BootstrapDialog.show({
  2. title: 'More dialog sizes',
  3. message: 'Hi Apple!',
  4. buttons: [{
  5. label: 'Normal',
  6. action: function(dialog){
  7. dialog.setTitle('Normal');
  8. dialog.setSize(BootstrapDialog.SIZE_NORMAL);
  9. }
  10. }, {
  11. label: 'Small',
  12. action: function(dialog){
  13. dialog.setTitle('Small');
  14. dialog.setSize(BootstrapDialog.SIZE_SMALL);
  15. }
  16. }, {
  17. label: 'Wide',
  18. action: function(dialog){
  19. dialog.setTitle('Wide');
  20. dialog.setSize(BootstrapDialog.SIZE_WIDE);
  21. }
  22. }, {
  23. label: 'Large',
  24. action: function(dialog){
  25. dialog.setTitle('Large');
  26. dialog.setSize(BootstrapDialog.SIZE_LARGE);
  27. }
  28. }]
  29. });

Rich message

BootstrapDialog supports displaying rich content, so you can even use a video clip as your message in the dialog.

  1. var $textAndPic = $('<div></div>');
  2. $textAndPic.append('Who\'s this? <br />');
  3. $textAndPic.append('<img src="./images/pig.ico" />');
  4. BootstrapDialog.show({
  5. title: 'Guess who that is',
  6. message: $textAndPic,
  7. buttons: [{
  8. label: 'Acky',
  9. action: function(dialogRef){
  10. dialogRef.close();
  11. }
  12. }, {
  13. label: 'Robert',
  14. action: function(dialogRef){
  15. dialogRef.close();
  16. }
  17. }]
  18. });

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().

  1. BootstrapDialog.show({
  2. message: 'Hi Apple!',
  3. closable: false,
  4. buttons: [{
  5. label: 'Dialog CLOSABLE!',
  6. cssClass: 'btn-success',
  7. action: function(dialogRef){
  8. dialogRef.setClosable(true);
  9. }
  10. }, {
  11. label: 'Dialog UNCLOSABLE!',
  12. cssClass: 'btn-warning',
  13. action: function(dialogRef){
  14. dialogRef.setClosable(false);
  15. }
  16. }, {
  17. label: 'Close the dialog',
  18. action: function(dialogRef){
  19. dialogRef.close();
  20. }
  21. }]
  22. });

More controls on closing a dialog.

By default, when option 'closable' is set to true, dialog can be closed by these ways: clicking outside the dialog, pressing ESC key, clicking the close icon on the right of dialog header. 
If you want your dialog closes only when the close icon in dialog header was clicked, try setting both of the options 'closeByBackdrop' and 'closeByKeyboard' to false.

  1. BootstrapDialog.show({
  2. message: 'Hi Apple!',
  3. message: 'You can not close this dialog by clicking outside and pressing ESC key.',
  4. closable: true,
  5. closeByBackdrop: false,
  6. closeByKeyboard: false,
  7. buttons: [{
  8. label: 'Close the dialog',
  9. action: function(dialogRef){
  10. dialogRef.close();
  11. }
  12. }]
  13. });

Disabling Animation

Setting option 'animate' to false to disable animation for the opening dialog. 
If you want to disable animation globally, try to do this: 
BootstrapDialog.configDefaultOptions({ animate: false });

  1. BootstrapDialog.show({
  2. message: 'There is no fading effects on this dialog.',
  3. animate: false,
  4. buttons: [{
  5. label: 'Close the dialog',
  6. action: function(dialogRef){
  7. dialogRef.close();
  8. }
  9. }]
  10. });

Auto spinning icon

Lazy guys must love this.

  1. BootstrapDialog.show({
  2. message: 'I send ajax request!',
  3. buttons: [{
  4. icon: 'glyphicon glyphicon-send',
  5. label: 'Send ajax request',
  6. cssClass: 'btn-primary',
  7. autospin: true,
  8. action: function(dialogRef){
  9. dialogRef.enableButtons(false);
  10. dialogRef.setClosable(false);
  11. dialogRef.getModalBody().html('Dialog closes in 5 seconds.');
  12. setTimeout(function(){
  13. dialogRef.close();
  14. }, 5000);
  15. }
  16. }, {
  17. label: 'Close',
  18. action: function(dialogRef){
  19. dialogRef.close();
  20. }
  21. }]
  22. });

Dialog Draggable

When option 'draggable' is set to true, your dialog can be moved by dragging on its header. 
If you would like to change the cursor shape of hovering on dialog header, you can try the following css lines: 

  1. .bootstrap-dialog .modal-header.bootstrap-dialog-draggable {
  2. cursor: move;
  3. }

  1. BootstrapDialog.show({
  2. title: 'Draggable Dialog',
  3. message: 'Try to drag on dialog title to move your dialog.',
  4. draggable: true
  5. });

Manipulating your dialog

  1. var dialog = new BootstrapDialog({
  2. message: function(dialogRef){
  3. var $message = $('<div>OK, this dialog has no header and footer, but you can close the dialog using this button: </div>');
  4. var $button = $('<button class="btn btn-primary btn-lg btn-block">Close the dialog</button>');
  5. $button.on('click', {dialogRef: dialogRef}, function(event){
  6. event.data.dialogRef.close();
  7. });
  8. $message.append($button);
  9. return $message;
  10. },
  11. closable: false
  12. });
  13. dialog.realize();
  14. dialog.getModalHeader().hide();
  15. dialog.getModalFooter().hide();
  16. dialog.getModalBody().css('background-color', '#0088cc');
  17. dialog.getModalBody().css('color', '#fff');
  18. dialog.open();

Adding additional css classes to your dialog

This is useful for applying effects to specific dialogs.
For example if you would like to give your 'login-dialog' a smaller size, you can do this way:

  1. <style>
  2. .login-dialog .modal-dialog {
  3. width: 300px;
  4. }
  5. </style>
  1. BootstrapDialog.show({
  2. title: 'Sign In',
  3. message: 'Your sign-in form goes here.',
  4. cssClass: 'login-dialog',
  5. buttons: [{
  6. label: 'Sign In Now!',
  7. cssClass: 'btn-primary',
  8. action: function(dialog){
  9. dialog.close();
  10. }
  11. }]
  12. });

Adding a description to your dialog (for accessibility)

This adds an 'aria-describedby' attribute to your dialog, which provides a description of the dialog for screen readers.

  1. BootstrapDialog.show({
  2. title: 'Add Description',
  3. message: 'The description is shown to screen readers.',
  4. description: 'This is a Bootstrap Dialog'
  5. });

Data binding

  1. var data1 = 'Apple';
  2. var data2 = 'Orange';
  3. var data3 = ['Banana', 'Pear'];
  4. BootstrapDialog.show({
  5. message: 'Hi Apple!',
  6. data: {
  7. 'data1': data1,
  8. 'data2': data2,
  9. 'data3': data3
  10. },
  11. buttons: [{
  12. label: 'See what you got',
  13. cssClass: 'btn-primary',
  14. action: function(dialogRef){
  15. alert(dialogRef.getData('data1'));
  16. alert(dialogRef.getData('data2'));
  17. alert(dialogRef.getData('data3').join(', '));
  18. }
  19. }]
  20. });

Dialog events

Please note that if you're going to use setters to configure event handlers, use dialog.onShow(function) and dialog.onHide(function).

  1. BootstrapDialog.show({
  2. message: 'Hello world!',
  3. onshow: function(dialogRef){
  4. alert('Dialog is popping up, its message is ' + dialogRef.getMessage());
  5. },
  6. onshown: function(dialogRef){
  7. alert('Dialog is popped up.');
  8. },
  9. onhide: function(dialogRef){
  10. alert('Dialog is popping down, its message is ' + dialogRef.getMessage());
  11. },
  12. onhidden: function(dialogRef){
  13. alert('Dialog is popped down.');
  14. }
  15. });

Stop closing your dialog.

Option 'onhide' gives you an opportunity to stop closing the dialog according to some conditions, making your 'onhide' callback returns false to stop closing the dialog. 
In the following example, the dialog closes only when your most favorite fruit is 'banana' (Case insensitive).

  1. BootstrapDialog.show({
  2. message: 'Your most favorite fruit: <input type="text" class="form-control">',
  3. onhide: function(dialogRef){
  4. var fruit = dialogRef.getModalBody().find('input').val();
  5. if($.trim(fruit.toLowerCase()) !== 'banana') {
  6. alert('Need banana!');
  7. return false;
  8. }
  9. },
  10. buttons: [{
  11. label: 'Close',
  12. action: function(dialogRef) {
  13. dialogRef.close();
  14. }
  15. }]
  16. });

More shortcut methods


Alert

  1. BootstrapDialog.alert('Hi Apple!');

Alert with callback

  1. BootstrapDialog.alert('Hi Apple!', function(){
  2. alert('Hi Orange!');
  3. });

Customizing dialog type, title, and more.

All options shown below are optional.

  1. BootstrapDialog.alert({
  2. title: 'WARNING',
  3. message: 'Warning! No Banana!',
  4. type: BootstrapDialog.TYPE_WARNING, // <-- Default value is BootstrapDialog.TYPE_PRIMARY
  5. closable: true, // <-- Default value is false
  6. draggable: true, // <-- Default value is false
  7. buttonLabel: 'Roar! Why!', // <-- Default value is 'OK',
  8. callback: function(result) {
  9. // result will be true if button was click, while it will be false if users close the dialog directly.
  10. alert('Result is: ' + result);
  11. }
  12. });

Confirm

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

Confirm with callback

  1. BootstrapDialog.confirm('Hi Apple, are you sure?', function(result){
  2. if(result) {
  3. alert('Yup.');
  4. }else {
  5. alert('Nope.');
  6. }
  7. });

Just like what we have done in alert, we can control confirm dialog more.

  1. BootstrapDialog.confirm({
  2. title: 'WARNING',
  3. message: 'Warning! Drop your banana?',
  4. type: BootstrapDialog.TYPE_WARNING, // <-- Default value is BootstrapDialog.TYPE_PRIMARY
  5. closable: true, // <-- Default value is false
  6. draggable: true, // <-- Default value is false
  7. btnCancelLabel: 'Do not drop it!', // <-- Default value is 'Cancel',
  8. btnOKLabel: 'Drop it!', // <-- Default value is 'OK',
  9. btnOKClass: 'btn-warning', // <-- If you didn't specify it, dialog type will be used,
  10. callback: function(result) {
  11. // result will be true if button was click, while it will be false if users close the dialog directly.
  12. if(result) {
  13. alert('Yup.');
  14. }else {
  15. alert('Nope.');
  16. }
  17. }
  18. });

I18N

To provide local messages for you needed, reset those messages below before using BootstrapDialog.

  1. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DEFAULT] = 'Information';
  2. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_INFO] = 'Information';
  3. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_PRIMARY] = 'Information';
  4. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_SUCCESS] = 'Success';
  5. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_WARNING] = 'Warning';
  6. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DANGER] = 'Danger';
  7. BootstrapDialog.DEFAULT_TEXTS['OK'] = 'OK';
  8. BootstrapDialog.DEFAULT_TEXTS['CANCEL'] = 'Cancel';
  9. BootstrapDialog.DEFAULT_TEXTS['CONFIRM'] = 'Confirmation';

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:
  1. BootstrapDialog.show({
  2. title: 'Say-hello dialog',
  3. message: 'Hello world!',
  4. buttons: [{
  5. id: 'btn-ok',
  6. icon: 'glyphicon glyphicon-check',
  7. label: 'OK',
  8. cssClass: 'btn-primary',
  9. autospin: false,
  10. action: function(dialogRef){
  11. dialogRef.close();
  12. }
  13. }]
  14. });
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().
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/80933
推荐阅读