【发布时间】:2011-04-15 08:17:17
【问题描述】:
我最近遇到了一种情况,我对在处理 JQueryUI 模态对话框时应该使用哪种技术感到有点困惑。
我有一个函数:ClearDay(weekID, ltDayID)。目前这负责创建一个带有两个按钮的对话框:确定和取消。
ok 将触发 ajax 调用,将 weekID 和 ltDayID 传递给服务器。
cancel 将清空对话框的 div 并调用.dialog('destroy') 在目标 div 上。
我的问题是:我应该使用以下哪种方法?
在每次调用时销毁/重新创建对话框 - 这样我就可以将参数传递给 ajax 调用,并且标记中的所有对话框只有一个 div
function ClearDay(weekID, ltDayID) {
$('#modalDialog').dialog({
autoOpen: true,
width: 300,
title: 'Confirm Delete',
modal: true,
buttons: [{
text: 'ok',
click: function (e) {
$(this).dialog('close');
$.ajax({
url: '/Shift/ClearDay',
type: 'POST',
cache: false,
data: { shiftWeekID: weekID, shiftLtDayID: ltDayID },
success: function (result) {
LoadShiftPattern(function (result) {
$('#weekContainer').html(result);
SelectLastUsedField();
});
}
});
}
},
{
text: 'cancel',
click: function (e) {
$('#errorList').empty();
$(this).dialog('close');
}
}],
open: function (e) {
$(this).html("Clicking ok will cause this day to be deleted.");
},
close: function (e) {
$(this).empty();
$(this).dialog('destroy');
}
});
}
只创建一次对话框,但标记中的每个对话框都有一个 div,使用 Close,并使用 Jquery Selectors 直接传递值
$(function() {
$('#confirmDeleteDialog').dialog({
autoOpen: false,
width: 300,
title: 'Confirm Delete',
modal: true,
buttons: [{
text: 'ok',
click: function (e) {
$(this).dialog('close');
$.ajax({
url: '/Shift/ClearDay',
type: 'POST',
cache: false,
data: { shiftWeekID: $('#weekIDInput').val(), shiftLtDayID: $('#dayIDInput').val()},
success: function (result) {
LoadShiftPattern(function (result) {
$('#weekContainer').html(result);
SelectLastUsedField();
});
}
});
}
},
{
text: 'cancel',
click: function (e) {
$('#errorList').empty();
$(this).dialog('close');
}
}],
open: function (e) {
$(this).html("Clicking ok will cause this day to be deleted.");
}
});
}
function ClearDay() {
$('#confirmDeleteDialog').dialog('open');
}
干杯,
詹姆斯
【问题讨论】:
标签: jquery jquery-ui modal-dialog