【问题标题】:Dialog box not showing up properly对话框未正确显示
【发布时间】:2014-12-08 21:10:05
【问题描述】:

我有一个用 JQuery 编码的非常简单的对话框,但它没有正确显示。单击“打开对话框”时会出现该框,但布局完全混乱,并且覆盖层没有按应有的方式覆盖整个页面。谁能告诉我这里的问题是什么?

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>


         <script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
         <script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>

         <script>       
$(document).ready(function () { 
    function popup() {
    var myPos = {
        my: "center top",
        at: "center top+210",
        of: window
    };

    //Set up the dialog box
    $(".popup").dialog({
        autoOpen: false,
        modal: true,
        position: myPos,
        resizable: false,
        draggable: false
    });
    }

    $('#d1').click(function () {
    $('.popup').dialog("open");
});

    popup();
    });
    </script>

    <style type="text/css">

.click {
    width: 100%;
    position: absolute;
    padding: 0 25px 0 25px;
    color: darkblue;
    cursor: pointer;
    margin-top: 210px;
}

    .ui-widget-overlay {
    background: #000;
    opacity: .8;
    -moz-opacity: 0.7;
    filter: alpha(opacity=70);
}

    .popup {
    font-size: 18px;
    margin-left: 50px;
    top: 50%;
    font-weight: bold;
    background-color: #fff;
    }



    .ui-dialog-titlebar {
    background: lightblue;
    color: black;
    border: 2px solid #D9D6D4;
    }


    </style>

    </head>

    <body>
    <div class="popup" id="box" title="Title">
    <br>Some random content</br>
    <br>More random content</br>
    <p> Blah blah </p>
    </div>
    <div class="click" id="d1">Open dialog</div>
    </body>
    </html>

【问题讨论】:

  • 这里似乎还可以jsfiddle.net/j08691/ts9huota
  • 是的,我知道它可以在 JSFiddle 和 CodePen 等其他类似网站中使用,但是当我从记事本中将它作为纯 HTML 文档拉出来时,格式全乱了。我不知道出了什么问题。是我与 Google CDN 一起使用的参考不正确吗?还是别的什么?
  • 打开浏览器的开发工具,看看控制台中有哪些错误信息。
  • 我按了 F12,但在控制台中没有看到任何错误消息?

标签: jquery html css dialog


【解决方案1】:

这是一个 CSS 问题。在head 部分添加以下内容

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/smoothness/jquery-ui.css" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 2017-12-19
    • 2020-02-16
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多