【问题标题】:jQuery ui Dialog not working when clicked to button单击按钮时jQuery ui对话框不起作用
【发布时间】:2014-08-12 11:04:57
【问题描述】:

我正在尝试修改基于 bootstrap 和 jquery 的网页模板。我试图在page 中添加一个对话框,但它不起作用。 (这是在“Open Positions”部分不起作用的按钮)

您可以在下面下载我的文件。您可以查看 index.html 文件。

我从link添加了这个javascript

$(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "explode",
            duration: 1000
        }
    });

    $( "#opener" ).click(function() {
        $( "#dialog" ).dialog( "open" );
    });
});

并为该 javascript 添加了以下行:

<div id="dialog" title="Contact Us">
    <p>info@info.info</p>
</div>
<button id="opener">Open Dialog</button>

为什么它不起作用?

另一个问题; 不使用这个 jquery ui 组件,我如何才能从“空缺职位”部分跳转到“联系我们”部分的内容?这也是我想知道的,因为它们都在同一个 html 文件中。

【问题讨论】:

    标签: javascript jquery html jquery-ui twitter-bootstrap


    【解决方案1】:

    你试过show吗?

    $( "#opener" ).click(function() {
        $( "#dialog" ).dialog( "show" );
    });
    

    在您的文件中出现错误:对 CSS 的引用不正确:

    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
    <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
    

    有两次对 jQuery 的额外引用导致了该问题。请删除其他版本的jQuery并将所有脚本移至底部。

    【讨论】:

    • @TimurAykutYILDIRIM 尝试删除autoOpen: false,这一行?
    • 它适用于您的代码@TimurAykutYILDIRIM,请查看:jsbin.com/difapezosiho/1/edit
    • 你是否添加了 CSS,顺便说一句?
    • 是的,我确实添加了 CSS。您介意下载我的问题中的文件吗?您可以看到其中有一个 index.html 文件。这些javascript代码在那个文件和jsbin的contary中,它们在那里不起作用
    • 在你的代码中,它写着$ is undefined,这意味着你忘了包含jQuery?让我再检查一次。
    猜你喜欢
    • 1970-01-01
    • 2011-07-10
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    相关资源
    最近更新 更多