javascript jQueryUI 对话框不起作用 - 为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10785741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:01:23  来源:igfitidea点击:

jQueryUI Dialog Box not working - Why?

javascriptjqueryjquery-uidialog

提问by Tomi Seus

I just can't figure this one out. The Dialog Box doesn't popup. I've tried all sorts of things but it just doesn't work. Here's my code:

我就是想不通这个。对话框不会弹出。我已经尝试了各种各样的事情,但它就是行不通。这是我的代码:

<head>
    <script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="/js/jquery-ui-1.8.20.custom.min.js"></script>
</head>
<body>
<script>
$(function() {
    // Dialog
    $('#dialog').dialog({
            autoOpen: false,
            width: 600,
            buttons: {
                    "Ok": function() {
                            $(this).dialog("close");
                    },
                    "Cancel": function() {
                            $(this).dialog("close");
                    }
            }
    });

    // Dialog Link
    $('#dialog_link').click(function(){
            $('#dialog').dialog('open');
            return false;
    });
});  
</script>

<a href="#" id="dialog_link">Open Dialog</a>

<div id="dialog">This should popup</div>
</body>

What's wrong here? Any help appreciated.

这里有什么问题?任何帮助表示赞赏。

回答by Lakhan

Try to use this it might be work.

尝试使用它可能会奏效。

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>

回答by Gaurav Agrawal

Where is jquery.ui.dialog.jsin this scode?????

jquery.ui.dialog.js这个 scode在哪里????

Please add this file into code as script tag....

请将此文件添加到代码中作为脚本标签....

you can put this JS file from here :

你可以把这个 JS 文件从这里放:

http://jqueryui.com/ui/jquery.ui.dialog.js

http://jqueryui.com/ui/jquery.ui.dialog.js

回答by Taha Paksu

<script></script>is not enough. Should be <script type="text/javascript"></script>

<script></script>是不足够的。应该<script type="text/javascript"></script>

回答by thecodeparadox

I think the scripttag just after bodymissing type="text/javascript". ie. <body><script type="text/javascript">...

我觉得这个script标签就在body失踪之后type="text/javascript"。IE。<body><script type="text/javascript">...

回答by silppuri

You have to include the script block after the

您必须在之后包含脚本块

<a href="#" id="dialog_link">Open Dialog</a>
<div id="dialog">This should popup</div>

block just before the body element and it should work.

块就在 body 元素之前,它应该可以工作。

You have to include also all the styling of the jQuery UI so that it looks nicer.

您还必须包含 jQuery UI 的所有样式,以便它看起来更好。

回答by Narayana Nagireddi

I have a same problem. It is probably a compatibility issue, try including the below instead of what you have

我有同样的问题。这可能是兼容性问题,请尝试包含以下内容而不是您拥有的内容

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

Also to display the dialog properly, replace jquery-ui-1.8.xx.custom.cssto match the jquery-ui.min.jsversion, I could not find a google ajax link.

还要正确显示对话框,替换jquery-ui-1.8.xx.custom.css以匹配jquery-ui.min.js版本,我找不到 google ajax 链接。

I want to find an alternative solution but no idea if I can find one.

我想找到另一种解决方案,但不知道是否能找到。