【问题标题】:Modal-dialog won't hide on page load模态对话框不会在页面加载时隐藏
【发布时间】:2011-09-27 18:29:07
【问题描述】:

我正在尝试创建一个模式对话框来仅显示内容(某种或其他的 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>

我做错了什么?

【问题讨论】:

  • 您是否以正确的顺序包含 jQueryUI.js?似乎它根本不起作用,所以也许您无权访问 jQueryUI。

标签: jquery jquery-ui jquery-dialog


【解决方案1】:

像这样使用 css 隐藏 div:

<div id="dialog" style="display:none;">This is my dialog that should be hidden until called</div>

现在它只会在被调用时显示。

【讨论】:

    【解决方案2】:

    你应该将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;
        });
    
    });
    

    【讨论】:

    • 试过了,我的对话框仍然内联显示并且没有隐藏。不过还是谢谢。
    • 嗨斯蒂尔,你有没有解决加载对话框可见的问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多