【问题标题】:Object doesn't support property or method 'confirm'对象不支持属性或方法“确认”
【发布时间】:2016-08-20 05:51:42
【问题描述】:

我有一个 WebForm,它继承自 MasterPage,在 WebForm 中我使用了 jQuery 和 JavaScript,因为我想创建一个带有自定义按钮的 dialog box,并且是默认的confirm() 方法不允许任何更改,所以我使用了来自 this website 的资源和代码。我不确定将 JS 源放在哪里,所以我把它们放在中间(如果我做错了请告诉我):

<asp:Content ID="Content2" ContentPlaceHolderID="CSS" runat="server">
</asp:Content>

我从参考资料中得到的来源是:

<script src="~/jquery.confirm.js"></script>
<script src="~/jquery.confirm.min.js"></script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>

正如从参考中复制的一样,这是我的 jQuery dialog box:

$("#Button1").confirm({
    title: "Confirmation Message",
    text: "Are you sure that the information you have entered is accurate?",
    confirm: function (button) {
        return true;
    },
    cancel: function (button) {
        return false;
    },
    confirmButton: "Yes",
    cancelButton: "No"
});

每当我尝试运行我的代码时,总会弹出此错误:

对象不支持“确认”属性或方法。

我尝试过使用各种 JS 源和 jQueries,因为我是新手,但它们都不起作用。我该如何解决这个问题?

【问题讨论】:

  • 为什么你把confirm.min,js和confirm.js这两个文件都包含进去了??只需要一个

标签: javascript jquery asp.net .net webforms


【解决方案1】:

试试这个:

$('#Button1').on('click', function () {
$.confirm({
    title: "Confirmation Message",
    text: "Are you sure that the information you have entered is accurate?"
    confirm: function (button) {
        return true;
    },
    cancel: function (button) {
        return false;
    },
    confirmButton: "Yes",
    cancelButton: "No"
});
});

【讨论】:

  • 首先尝试删除任何 js 文件,无论是确认.min、js 或确认.js...如果它不起作用,请尝试上述解决方案..我希望任何一个都可以工作。跨度>
  • 我尝试了您建议的第一个方法,但两个文件也不能单独工作,并弹出与提到的相同的错误消息。然后,我尝试了您的解决方案。没有报错也没有对话框,直接提交了。
猜你喜欢
  • 2019-07-05
  • 2015-04-14
  • 2020-09-03
  • 2015-04-09
  • 2014-01-12
  • 2016-08-20
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多