【发布时间】:2015-09-13 12:58:34
【问题描述】:
使用此代码,我想在单击按钮时显示一个 jQuery UI 对话框。但是,当页面加载时,对话框的文本会显示一小段时间。实现这一点的正确方法是什么? 我的html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
.. html code ..
<button id="helpbutton" title="">Help</button>
<div id="helpdialog" title="Help dialog">
<p>Text in the dialog will be visible for a short time when the page loads</p>
</div>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script type="text/javascript" src="myJsFile.js"></script>
</body>
</html>
如您所见,出于性能原因,我在结束之前调用我的外部脚本。
myJsFile.js:
//Fire up the help dialog when the help button is pressed
jQuery(function() {
jQuery( "#helpdialog" ).dialog({
autoOpen: false
});
jQuery( "#helpbutton" ).click(function() {
jQuery( "#helpdialog" ).dialog( "open" );
});
});
解决方案(感谢 krzmig):在 CSS 文件或部分中使用此 CSS 代码
#helpdialog {
display: none;
}
【问题讨论】:
-
控制台有错误吗?
-
你的代码没有问题,见fiddle
标签: javascript html jquery-ui dialog popup