JQuery 第二次单击时对话框未打开
JQuery dialog not opening second time on click
这是我打开 jquery 对话框的代码。它第一次工作(打开)但不是第二次(不打开)。有人问了一个类似的问题 here 但这对我不起作用
function LoadGridView(id, row) {
var dlg = jQuery('#Edit').load('Edit.aspx');
dlg.dialog({
autoOpen: false,
modal: true,
show: 'slide',
close: 'slide',
width: 400,
height: 160,
buttons: {
"cancel": function() {
dlg.dialog("close");
}
}
});
dlg.dialog("open");
}
第二次打开时你的dlg作用域不存在,需要全局存储
// global var to hold dlg
var dlg;
$(document).ready(function() {
// get element and store it in dlg global var so that its scope may retain
dlg = $("[id$='Edit']");
dlg.dialog({
autoOpen: false,
modal: true,
show: 'slide',
close: 'slide',
width: 400,
height: 160,
buttons: {
"cancel": function() {
dlg.dialog("close");
}
}
});
});
这是我打开 jquery 对话框的代码。它第一次工作(打开)但不是第二次(不打开)。有人问了一个类似的问题 here 但这对我不起作用
function LoadGridView(id, row) {
var dlg = jQuery('#Edit').load('Edit.aspx');
dlg.dialog({
autoOpen: false,
modal: true,
show: 'slide',
close: 'slide',
width: 400,
height: 160,
buttons: {
"cancel": function() {
dlg.dialog("close");
}
}
});
dlg.dialog("open");
}
第二次打开时你的dlg作用域不存在,需要全局存储
// global var to hold dlg
var dlg;
$(document).ready(function() {
// get element and store it in dlg global var so that its scope may retain
dlg = $("[id$='Edit']");
dlg.dialog({
autoOpen: false,
modal: true,
show: 'slide',
close: 'slide',
width: 400,
height: 160,
buttons: {
"cancel": function() {
dlg.dialog("close");
}
}
});
});