2017-07-31 69 views
0

我使用,如果用户点击另一个对话框上opens.Here是我的全部代码的jQuery创建一个对话框:为什么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

我想你的问题是** $( '#result_map2')HTML(数据); **测试它 – gaetanoM

+0

意味着数据。没有生成?@gaetanoM – BibanCS

+0

不是。我假设这一行代码覆盖了整个原始元素。 – gaetanoM

回答

0

得到了答案。需要调用preventDefault()以防止element.Like的默认操作:

$(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);