jQuery UI: How can I send a set of common options to .dialog()?
Is it possible to send a set of common options:
var commonVars = {
autoOpen: false,
draggable: false,
resizable: false,
show: 'fade',
hide: 'fade'
};
To dialog boxes:
$('#dialog_1').dialog({
//Common vars go here somehow
width: 275,
height: 170,
dialog开发者_如何学PythonClass: "class1 class2"
});
$('#dialog_2').dialog({
//Common vars go here somehow
width: 600,
height: 350,
dialogClass: "class3 class4"
});
$.extend()
Example:
var object1 = {
//Common vars go here somehow
width: 275,
height: 170,
dialogClass: "class1 class2"
};
var object2 = {
//Common vars go here somehow
width: 600,
height: 350,
dialogClass: "class3 class4"
}
var commonVars = {
autoOpen: false,
draggable: false,
resizable: false,
show: 'fade',
hide: 'fade'
};
$.extend(object1, commonVars);
$.extend(object2, commonVars);
$('#dialog_1').dialog(object1);
$('#dialog_2').dialog(object2);
Figured it out, kind of on accident. So for anyone wondering the same thing, you can put the commonVars
variable before each dialog's options bracket:
var commonVars = {
autoOpen: false,
draggable: false,
resizable: false,
show: 'fade',
hide: 'fade'
};
$('#dialog_1').dialog(commonVars,{
width: 275,
height: 170,
dialogClass: "class1 class2"
});
Why don't you just do $('#dialog_1').dialog(commonVars)
?
精彩评论