Javascript UI对话框不会第一次打开
我正在尝试使用jQueryUI对话框。但它不会第一次打开。考虑:Javascript UI对话框不会第一次打开,javascript,jquery,dialog,Javascript,Jquery,Dialog,我正在尝试使用jQueryUI对话框。但它不会第一次打开。考虑: <html> <head> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" /> <script src="https://ajax.googleapis.com/ajax/li
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="dialog.js"></script>
</head>
<body>
<p>Hello</p>
<div id="dialog" title="Alert" style="display: none;"></div>
</body>
</html>
这将只显示第二个对话框,第一个对话框(文本为“1”)似乎被忽略
另请参见。第二个是替换
#对话框的内容。如果您想等待对话框关闭,您必须将其放入onClose
选项中。@Barmar当然,这是一个愚蠢的问题。我试图将问题与更大的代码隔离开来。现在,更大的代码似乎与此类似,但没有第二个对话框,只有第一个。。但是,对话框仍然没有打开。但是如果我在它前面放一个javascriptalert()
,它就会打开。有什么想法吗?听起来你的脚本好像进入了一个循环,所以它永远不会返回到主事件循环。@Barmar谢谢你的帮助!我想我现在已经更好地隔离了这个问题。我想我会发布一个新问题。我应该删除这个问题吗?是的,删除这个就好了。我已经回答了你的另一个问题。
$(document).ready(function(){
showAlert("1");
showAlert("2");
});
function showAlert(str) {
$( "#dialog" ).html(str);
$( "#dialog" ).dialog({
modal: true,
title: "Alert",
buttons: {
"OK": function() {
document.getElementById("submit").value="Submit";
$( this ).dialog( "close" );
}
}
});
}