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