我正在使用jquery创建一个对话框,如果用户单击另一个对话框,则打开该对话框。这是我的完整代码:
$(document).ready(function() {
var a = document.getElementById("alphasvg");
a.addEventListener("load", function() {
var svgDoc = a.contentDocument;
var dom1 = svgDoc.getElementById("BD-B");
dom1.addEventListener("mousedown", function() {
var action = "select";
var reg_name = $(this).attr("title");
fetchSector();
function fetchSector() {
$.ajax({
url: "select_sector_map.php",
method: "POST",
data: {
action: action,
reg_name: reg_name
},
success: function(data) {
$('#result_map').html(data);
}
});
};
$("#result_map").dialog({
title: "Region: Chittagong",
width: 600,
height: 600,
model: true,
buttons: {
Close: function() {
$(this).dialog('close');
}
}
});
});
$(document).on('click', '.selected_pla', function() {
var new_pla = $(this).attr("value");
selBat();
function selBat() {
var action = "select";
$.ajax({
url: "select_battelion_map.php",
method: "POST",
data: {
action: action,
new_pla: new_pla
},
success: function(data) {
$('#result_map2').html(data);
}
});
};
$("#result_map2").dialog({
title: "Suggestions",
height: 600,
width: 600,
model: true,
buttons: {
Close: function() {
$(this).dialog('close');
}
}
});
});
}, false);
}, false);
我的问题是,当我点击第一个对话框的按钮时,第二个对话框出现并立即关闭。我正在粘贴我的完整代码,以便更好地理解我正在使用.svg这可能是问题的根源。请帮忙!
答案 0 :(得分:0)
得到了答案。需要调用preventDefault()来阻止元素的默认操作。喜欢:
$(document).ready(function() {
var a = document.getElementById("alphasvg");
a.addEventListener("load", function() {
var svgDoc = a.contentDocument;
var dom1 = svgDoc.getElementById("BD-B");
dom1.addEventListener("mousedown", function() {
var action = "select";
var reg_name = $(this).attr("title");
fetchSector();
function fetchSector() {
$.ajax({
url: "select_sector_map.php",
method: "POST",
data: {
action: action,
reg_name: reg_name
},
success: function(data) {
$('#result_map').html(data);
}
});
};
$("#result_map").dialog({
title: "Region: Chittagong",
width: 600,
height: 600,
model: true,
buttons: {
Close: function() {
$(this).dialog('close');
}
}
});
});
$(document).on('click', '.selected_pla', function(e) {
var new_pla = $(this).attr("value");
selBat();
function selBat() {
var action = "select";
$.ajax({
url: "select_battelion_map.php",
method: "POST",
data: {
action: action,
new_pla: new_pla
},
success: function(data) {
$('#result_map2').html(data);
}
});
};
$("#result_map2").dialog({
title: "Suggestions",
height: 600,
width: 600,
model: true,
buttons: {
Close: function() {
$(this).dialog('close');
}
}
});
e.preventDefault();
});
}, false);
}, false);