CreateTemplate,OpenTemplate和许多其他Jquery对话框设置大部分时间使用相同的设置,但高度和宽度都有例外。
是否可以通过jquery .dialog()函数对所有键/值设置的数组进行排序,以便我可以轻松地传递此数组?
$(document).ready(function () {
// I would like to setup here sort of an array with properties and values
// as basis for each click-handler
/************************* Open template ****************************/
$('#OpenTemplate').click(function (e) {
e.preventDefault();
var link = this;
$('#MyDialog').dialog({
open: function (e) { $(this).load($(link).attr('href')); },
title: link.innerHTML,
autoOpen: true,
modal: true,
show: 'fade',
hide: 'fade',
width: 250,
height: 200,
buttons:
{
"OK": function () { openTemplate($(this), $('form', this)); },
"Cancel": function () { $(this).dialog("close"); }
}
});
});
/************************* Create template ****************************/
$('#CreateTemplate').click(function (e) {
e.preventDefault();
var link = this;
$('#MyDialog').dialog({
open: function (e) { $(this).load($(link).attr('href')); },
title: link.innerHTML,
autoOpen: true,
modal: true,
show: 'fade',
hide: 'fade',
width: 250,
height: 200,
buttons:
{
"OK": function () { createTemplate($(this), $('form', this)); },
"Cancel": function () { $(this).dialog("close"); }
}
});
});
});
答案 0 :(得分:0)
我会尝试做这样的事情:
var dialogObject = { title: 'Title', width: 250 };
$('#CreateTemplate').dialog(dialogObject);
此对象可以包含您知道在所有对话框中都相同的所有值。如果您想要更改高度,可以通过执行以下操作来更改现有对话框:
$('#dialog-confirm').attr('height', '250');
如果需要在dialogObject中添加按钮:
var dialogObject = {
title: 'Title',
width: 250,
buttons: {
"Ok": function()
{
$(this).dialog("close");
}
}
};