【问题标题】:open jquery modal dialog on page load在页面加载时打开 jquery 模式对话框
【发布时间】:2009-02-07 01:14:38
【问题描述】:

我有一个页面,我希望它在页面加载后立即在模式对话框(jquery UI 对话框)中显示一些内容。

  $(document).ready(function(){
    $("#example").dialog();
  });

<div id="example" class="flora" title="This is my title">
    I'm in a dialog!
</div>

谢谢

【问题讨论】:

  • 那么您提供的代码有什么问题?它不工作还是......?据我所知,这将非常有效。我建议你使用 $(function() { 而不是 $(document).ready(function(){。它更短更容易阅读。:P
  • 我在下面支持他们的问题。看起来不错,请问您遇到了什么问题

标签: javascript jquery jquery-ui


【解决方案1】:

您的 div 标签格式不正确,需要关闭。以下对我有用,但它需要适当的 CSS 文件。

<html>
<head>
<script type="text/javascript" language="javascript"
        src="jquery/jquery.js"></script>
<script type="text/javascript" language="javascript"
        src="jquery/jquery.ui.js"></script>
<script type="text/javascript" language="javascript">
    $(document).ready(function(){
        $("#example").dialog({modal: true});
    });
</script>
</head>
<body>
    <div id="example" class="flora" title="This is my title">
        I'm in a dialog!
    </div>
</body>
</html>

【讨论】:

    【解决方案2】:

    韦恩汗是对的

    默认行为是在您调用 dialog() 时打开,除非您将 autoOpen 设置为 false。

    虽然默认对话框不是模态对话框,但 tvanfosson 几乎是正确的。要显示模式窗口,您必须将 modal 选项设置为 true

    为了说明,这里是我今晚工作的small project 的删减节选:

    ...
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="./jquery-ui-personalized-1.6rc6.min.js"></script>
    <script type="text/javascript" src="./init.js"></script>
    <link rel="stylesheet" href="./css.css" type="text/css" />
    <script type="text/javascript">
        $(function() {
            $('#exampleNode').dialog({
                modal: 'true'
            });
        });
    </script>
    ...
    

    供您参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多