【发布时间】:2017-01-26 20:39:42
【问题描述】:
我有一个 2 层的传单地图,当我单击“保存”按钮时,它会打开一个对话框,其中包含一个表单,可以将一些信息发送到我的数据库。
当我的第一层被选中并单击“保存”按钮时,它会打开与我的第一层对应的对话框。
但是,当我的第二层被选中并单击“保存”按钮时,它会打开与我的第二层相对应的对话框,而且还会打开我之前为第一层打开的表单。
那么,是否可以阻止打开此表单? 因为如果我做一个.dialog('close'),它在表单上不对应,它可以工作,但我们可以看到它打开然后关闭,所以这不是很好!
我已经测试过 .dialog("destroy");和 .remove();但它会删除我在 DOM 中的对话框,之后我无法再打开它们。
所以,这里有一些代码:
//Code in the oneachfeature function from my layer1
$('#save').on('click',function(e){
var dialog1 = $("#dialog1").dialog({
autoOpen: false,
modal: true,
show: {
effect: "blind",
duration: 500
},
hide: {
effect: "blind",
duration: 500
},
close: function(event, ui) {
//$(this).dialog("destroy");
//$(this).dialog("close");
//$(this).remove();
},
height: 400,
width: 500,
modal: true,
position: {
my: "center center",
at: "center center",
of: "#map"
},
buttons: {
Valider: function() {
// Ajax to send informations in the form
}, // end of valider
Annuler: function() {
dialog1.dialog("close");
},
}, // end of buttons
}); // end of dialog
dialog1.dialog("open");
$("#dialog2").dialog('close');
}); // end of save
//Code in the oneachfeature function from my layer2
$('#save').on('click',function(e){
var dialog2 = $("#dialog2").dialog({
autoOpen: false,
modal: true,
show: {
effect: "blind",
duration: 500
},
hide: {
effect: "blind",
duration: 500
},
close: function(event, ui) {
//$(this).dialog("destroy");
//$(this).dialog("close");
//$(this).remove();
},
height: 400,
width: 500,
modal: true,
position: {
my: "center center",
at: "center center",
of: "#map"
},
buttons: {
Valider: function() {
// Ajax to send informations in the form
}, // end of valider
Annuler: function() {
dialog2.dialog("close");
},
}, // end of buttons
}); // end of dialog
dialog2.dialog("open");
$("#dialog1").dialog('close');
}); // end of save
【问题讨论】:
标签: javascript jquery jquery-ui dialog