【问题标题】:jquery ui dialog box not opening in html on click of a link单击链接时,jquery ui 对话框未在 html 中打开
【发布时间】:2015-04-27 13:22:04
【问题描述】:

我试图在单击链接时在 html 页面中打开一个对话框,但它向我显示了一个错误,例如对象不支持单击 ie 时的属性或方法“对话框”。

请检查我下面的代码

源文件

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

对话框代码

$("#link").click(function(c){

                e.preventDefault();
          var dialog = $('<p>Are you sure?</p>').dialog({

            buttons: {
                "Yes": function() {alert('you chose yes');},
                "No":  function() {alert('you chose no');},
                "Cancel":  function() {
                    dialog.dialog('close');
                }
            }
        });
            }); 
            });

【问题讨论】:

    标签: javascript jquery html css jquery-ui


    【解决方案1】:

    用“e”替换“c”并删除末尾的右括号。你吃的太多了。

    $("#link").click(function(e){
    
                e.preventDefault();
          var dialog = $('<p>Are you sure?</p>').dialog({
    
            buttons: {
                "Yes": function() {alert('you chose yes');},
                "No":  function() {alert('you chose no');},
                "Cancel":  function() {
                    dialog.dialog('close');
                }
            }
        });
            }); 
    

    【讨论】:

    • 我也使用了你的小提琴代码。但我仍然在 IE 上遇到同样的错误
    • 试试这个:jsfiddle.net/2xaz90y7/6/embedded/result我认为你的脚本没有被加载,试试 https
    • hmm.its 以纯 html 加载,但是当我放入我的 jsp 时,它会抛出错误
    【解决方案2】:

    您需要设置一个 div 作为对话框,如下例所示:

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>jQuery UI Dialog - Animation</title>
      <link rel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
      <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
      <link rel="stylesheet" href="/resources/demos/style.css">
      <script>
      $(function() {
        $( "#dialog" ).dialog({
          autoOpen: false,
          show: {
            effect: "blind",
            duration: 1000
          },
          hide: {
            effect: "explode",
            duration: 1000
          }
        });
     
        $( "#opener" ).click(function() {
          $( "#dialog" ).dialog( "open" );
        });
      });
      </script>
    </head>
    <body>
     
    <div id="dialog" title="Basic dialog">
      <p>This is an animated dialog which is useful for displaying information.     The dialog window can be moved, resized and closed with the 'x' icon.</p>
    </div>
     
    <button id="opener">Open Dialog</button>
     
     
    </body>
    </html>

    Here's a jsbin with a working example with buttons

    【讨论】:

    • 但是我需要在单击一个未发生的链接时运行此对话框,先生。
    • 它按照您提供的方式工作,但是当添加点击功能时它停止工作
    • 这个错误是否与我正在链接的脚本源有关
    • 我不知道。我在上面粘贴的确切代码对您有用吗?那将是首先要测试的东西。如果确切的代码有效,则替换为您的脚本源,然后再次测试。
    • 仍然是相同的先生,更新了代码....问题可能出在脚本源上。不是
    猜你喜欢
    • 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
    相关资源
    最近更新 更多