简体   繁体   中英

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,
    dialogClass:    "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) ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM