jQuery UI对话框-不会第一次打开

问题描述

| 我使用jQuery UI对话框作为确认框,当您单击链接时,该对话框将打开并带有问题和两个按钮。 但是对话框有一些加载问题。当我第一次访问该页面时,该对话框将不会打开。当我按F5再试一次时,它工作正常。 这是我的代码
<script type=\"text/javascript\">
$(document).ready(function() {
var url;

$( \"#dialog\" ).dialog( {
    autoOpen: false,resizable: false,modal: true,buttons: {
        \"Yes\": function() {
            $(this).dialog(\"close\");
            window.location.href = url;
        },\"No\": function() {
            $(this).dialog(\"close\");
        }
    }
});

$(\"a.supportClub\").click(function(e) {
    e.preventDefault();
    url = e.target;
    $(\"#dialog\").dialog(\"open\");
});  
});
</script>


<div id=\"dialog\" title=\"Support club\" style=\"display: none\">
    <p>The question</p>
</div>   

<a href=\"?supportClub=5\" class=\"button right supportClub\">Support</a>
希望有人能帮助我。 谢谢!     

解决方法

$(\"a.supportClub\").click(function(e) {
    e.preventDefault();
    url = e.target;
    $(\'#dialog\').dialog(\'destroy\');
    $(\"#dialog\").dialog();
}); 
    ,尝试这个 :
<script type=\"text/javascript\">
$(document).ready(function() {
function showDialog(url){
     $( \"#dialog\" ).dialog( {
        resizable: false,modal: true,buttons: {
            \"Yes\": function() {
                $(this).dialog(\"close\");
                window.location.href = url;
            },\"No\": function() {
                $(this).dialog(\"destroy\");
            }
        }
    });
  }

$(\"a.supportClub\").click(function(e) {
    e.preventDefault();
    showDialog(e.target);
  });  
});
</script>