是否可以发送一组常用选项:
var commonVars = {
autoOpen: false,
draggable: false,
resizable: false,
show: 'fade',
hide: 'fade'
};
到对话框:
$('#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"
});
答案 0 :(得分:5)
示例:
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);
答案 1 :(得分:1)
想出来,有点意外。所以对于想知道同样事情的人,你可以在每个对话框的选项括号之前放置commonVars
变量:
var commonVars = {
autoOpen: false,
draggable: false,
resizable: false,
show: 'fade',
hide: 'fade'
};
$('#dialog_1').dialog(commonVars,{
width: 275,
height: 170,
dialogClass: "class1 class2"
});
答案 2 :(得分:0)
你为什么不这样做$('#dialog_1').dialog(commonVars)
?