赞
踩
<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 -->
这种使用的方式键值是太不方便了涩!
2. 所以就产生了一种简单的方式进行处理
BootstrapDialog.show({
message: 'Hi Apple!'
});
很多的默认的参数,简化了我们的操作的手段
其实创建后的结果,和我们第一步看到的那种是一样的,只是简化了我们的书写步骤!
如下,是一些参数
BootstrapDialog.defaultOptions = {
type: BootstrapDialog.TYPE_PRIMARY,
size: BootstrapDialog.SIZE_NORMAL,
cssClass: '',
title: null,
message: null,
nl2br: true,
closable: true,
closeByBackdrop: true,
closeByKeyboard: true,
closeIcon: '×',
spinicon: BootstrapDialog.ICON_SPINNER,
autodestroy: true,
draggable: false,
animate: true,
description: '',
tabindex: -1,
btnsOrder: BootstrapDialog.BUTTONS_ORDER_CANCEL_OK
};
以及我们可以覆盖一些默认的时间
var BootstrapDialog = function (options) {
this.defaultOptions = $.extend(true, {
id: BootstrapDialog.newGuid(),
buttons: [],
data: {},//保存的数据在dialog
onshow: null,//打开之前
onshown: null,//打开完成
onhide: null,//关闭之前
onhidden: null//关闭完成
}, BootstrapDialog.defaultOptions);
this.indexedButtons = {};
this.registeredButtonHotkeys = {};
this.draggableData = {
isMouseDown: false,
mouseOffset: {}
};
this.realized = false;
this.opened = false;
this.initOptions(options);
this.holdThisInstance();
};
// Button on click
$button.on('click', {dialog: this, $button: $button, button: button}, function (event) {
var dialog = event.data.dialog;
var $button = event.data.$button;
var button = $button.data('button');
if (button.autospin) {
$button.toggleSpin(true);
}
if (typeof button.action === 'function') {
return button.action.call($button, dialog, event);
}
});
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');
}
}]
});
getData: function (key) {
return this.options.data[key];
},
获得远程的数据,而不是写在本地上面的数据信息哦!
BootstrapDialog.show({
message: $('<div></div>').load('remote.html')
});
BootstrapDialog.show({
message: function(dialog) {
var $message = $('<div></div>');
var pageToLoad = dialog.getData('pageToLoad');
$message.load(pageToLoad);
return $message;
},
data: {
'pageToLoad': 'remote.html'
}
});
// 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();
这个下面也是可以的,但是在自己自动的打开了对话框了
// You can use dialogInstance later.
var dialogInstance = BootstrapDialog.show({
message: 'Hello Banana!'
});
var types = [BootstrapDialog.TYPE_DEFAULT,
BootstrapDialog.TYPE_INFO,
BootstrapDialog.TYPE_PRIMARY,
BootstrapDialog.TYPE_SUCCESS,
BootstrapDialog.TYPE_WARNING,
BootstrapDialog.TYPE_DANGER];
$.each(types, function(index, type){
BootstrapDialog.show({
type: type,
title: 'Message type: ' + type,
message: 'What to do next?',
buttons: [{
label: 'I do nothing.'
}]
});
});
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);
}
}]
});
var dialog = new BootstrapDialog({
message: function(dialogRef){
var $message = $('<div>OK, this dialog has no header and footer, but you can close the dialog using this button: </div>');
var $button = $('<button class="btn btn-primary btn-lg btn-block">Close the dialog</button>');
$button.on('click', {dialogRef: dialogRef}, function(event){
event.data.dialogRef.close();
});
$message.append($button);
return $message;
},
closable: false
});
dialog.realize();
dialog.getModalHeader().hide();
dialog.getModalFooter().hide();
dialog.getModalBody().css('background-color', '#0088cc');
dialog.getModalBody().css('color', '#fff');
dialog.open();
<style>
.login-dialog .modal-dialog {
width: 300px;
}
</style>
BootstrapDialog.show({
title: 'Sign In',
message: 'Your sign-in form goes here.',
cssClass: 'login-dialog',
buttons: [{
label: 'Sign In Now!',
cssClass: 'btn-primary',
action: function(dialog){
dialog.close();
}
}]
});
BootstrapDialog.show({
message: 'Hello world!',
onshow: function(dialogRef){
alert('Dialog is popping up, its message is ' + dialogRef.getMessage());
},
onshown: function(dialogRef){
alert('Dialog is popped up.');
},
onhide: function(dialogRef){
alert('Dialog is popping down, its message is ' + dialogRef.getMessage());
},
onhidden: function(dialogRef){
alert('Dialog is popped down.');
}
});
BootstrapDialog.show({
message: 'Your most favorite fruit: <input type="text" class="form-control">',
onhide: function(dialogRef){
var fruit = dialogRef.getModalBody().find('input').val();
if($.trim(fruit.toLowerCase()) !== 'banana') {
alert('Need banana!');
return false;
}
},
buttons: [{
label: 'Close',
action: function(dialogRef) {
dialogRef.close();//对于对话框内部的实例对象的引用
}
}]
});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。