jQuery UI Dialog - Won't open the first time

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 18:10:57

问题


I'm using the jQuery UI Dialog as a confirm box, when you click a link the dialog will open with the question and two buttons. But I've got some load problems with the dialog. When I visit the page for the first time, the dialog won't open. When I press F5 and try it again, it works fine.

This is my code:

<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>

Hopefully could someone help me.

Thank you!


回答1:


$("a.supportClub").click(function(e) {
    e.preventDefault();
    url = e.target;
    $('#dialog').dialog('destroy');
    $("#dialog").dialog();
}); 



回答2:


try this :

<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>


来源:https://stackoverflow.com/questions/6111637/jquery-ui-dialog-wont-open-the-first-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!