【问题标题】:Unable to create a JQuery Dialog无法创建 JQuery 对话框
【发布时间】:2014-07-16 15:47:03
【问题描述】:

我试图让一个 JQuery 对话框出现,并立即收到错误 $(...).dialog() doesn't exist。我的谷歌搜索显示这通常是由加载 2 个不同的 JQuery 库引起的,但我文件中唯一的脚本标签是用于 JQuery 和 Twitter Bootstrap。这是我的代码(包括改编自 How to implement "confirmation" dialog in Jquery UI dialog? 的对话代码)..

<script src="jquery-1.10.1.min.js"></script>
<script src="js/bootstrap.js"></script>
...

<script>
$(function(){
$("#dialog").dialog({
    autoOpen: false,
    modal: true
});
$(".deleteLink").click(function(e){
    e.preventDefault();
    var targetUrl = $(this).attr("href");

    $("#dialog").dialog({
        buttons : {
            "Yes" : function(){
                window.location.replace(targetUrl);
            },
            "No" : function(){
                $(this).dialog("close");
            }
        }
    });
});
});
</script>

除了加载多个库或引导程序可能会提供某种干扰之外,还有其他原因可能会导致我收到此错误吗?

【问题讨论】:

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


    【解决方案1】:

    您正在尝试使用 jQueryUI 的 dialog() 方法和属性,但您已经包含了 Bootstrap 库。要使用 Bootstrap 对话框,该方法称为 modal()

    Bootstrap Modal docs

    请注意,属性完全不同。如果您想使用 jQuery UI dialog() 方法,则需要包含 jQueryUI 库,但请注意,这有时会导致 JS 和 CSS 中的 Bootstrap 不兼容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 2012-04-11
      • 1970-01-01
      相关资源
      最近更新 更多