我正在尝试创建一个模式对话框来显示内容(某种或其他类型的html):
<script>
$.fx.speeds._default = 1000;
$(function() {
$( "#dialog" ).dialog({
autoOpen: false,
closeOnEscape: true,
modal: true,
position: 'center',
width: 800,
height: 600,
show: "blind",
hide: "explode"
});
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
return false;
});
});
</script>
当我查看页面时,对话框是内嵌的而不是隐藏的。这是我的HTML:
<div id="dialog">This is my dialog that should be hidden until called</div>
<button id="opener">I Open the Dialog</button>
我做错了什么?
答案 0 :(得分:10)
使用css隐藏div:
<div id="dialog" style="display:none;">This is my dialog that should be hidden until called</div>
现在它只会在被召唤时显示。
答案 1 :(得分:8)
您应该将autoOpen
属性设置为false,下面是一些参考
http://jqueryui.com/demos/dialog/#option-autoOpen
这是一个例子
$(function() {
$( "#dialog" ).dialog({
closeOnEscape: true,
modal: true,
position: 'top',
width: 800,
height: 600,
show: "blind",
hide: "explode",
autoOpen: false ///added this line
});
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
return false;
});
});