【问题标题】:JQuery UI Dialog displaying, not working as dialogJQuery UI 对话框显示,不作为对话框工作
【发布时间】:2025-12-31 21:00:02
【问题描述】:

问题:

对话框 div 在没有按下按钮的情况下显示,并且在我按下它们时不会显示为覆盖。我把头发扯掉了,所以提前谢谢。

代码:

包括:

<script src="js/jquery-1.5.1.min.js"></script>
<script src="js/ui/jquery.ui.core.js"></script>
<script src="js/ui/jquery.ui.widget.js"></script>
<script src="js/ui/jquery.ui.position.js"></script>
<script src="js/ui/jquery.ui.autocomplete.js"></script>
<script src="js/ui/jquery.ui.dialog.js"></script>

CSS:

<link rel="stylesheet" type="text/css" href="css/jquery.ui.autocomplete.
<link rel="stylesheet" type="text/css" href="css/jquery.ui.all.
<link rel="stylesheet" type="text/css" href="css/jquery.ui.theme.
<link rel="stylesheet" type="text/css" href="css/jquery.ui.dialog.css" />

按钮:&lt;a class="phoneadder"&gt;Stuff&lt;/a&gt;

脚本:

<script>
        $( "#dialog-form" ).dialog({
            autoOpen: false,
            height: 300,
            width: 350,
            modal: true
        }
    );
        $( ".phoneadder" ).click(function() {
            $( "#dialog-form" ).dialog( "open" );
            return false;
        });
    </script>

对话框:

<div id="dialog-form" title="Create new phone">
    <p>All form fields are required.</p>

    <form>
    <fieldset>
        ...some html here
    </fieldset>
    </form>
</div>

【问题讨论】:

  • 你确定你粘贴了 css 吗?或者这只是一个错误?
  • 您的样式表中包含一些缺少的字符 - 我想这只是 c&p 遗漏的吗?
  • 我把它们放进去时它们消失了,但你明白了。

标签: javascript jquery html jquery-ui jquery-ui-dialog


【解决方案1】:

将初始化程序放在您的 document.ready 中,或作为简写:

$(function() { $("#dialog-form").dialog(autoOpen... ); } );

或者,确保您的脚本在创建 div 之后运行,就像在页脚中一样。

【讨论】:

    【解决方案2】:

    尝试将您的 jQuery 代码放入 $(document).ready 函数中,如下所示:

    $(document).ready(function () { 
    /// your code here
    
    });
    

    【讨论】:

      【解决方案3】:

      试试这个,

        $(function()
        {
          $( ".phoneadder" ).click(function() {
             $( "#dialog-form" ).dialog({
              height: xxx,
              width: xxx,
              modal: true
             });
             return false;
          });
        });
      

      【讨论】:

        【解决方案4】:

        你为什么不把对话框函数放在点击事件处理程序中呢?

        <script>
              $(function()
              {
                $( ".phoneadder" ).click(function() {
                   $( "#dialog-form" ).dialog({
                    height: 300,
                    width: 350,
                    modal: true
                   });
        
                   return false;
                });
              });
        </script>
        

        【讨论】: