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

Object doesn't support property or method 'confirm'

本文关键字:确认 方法 不支持 属性 对象      更新时间:2023-09-26

我有一个继承自MasterPageWebForm,在WebForm我使用了jQuery和JavaScript,这是我的新手,因为我想创建一个带有自定义按钮的dialog box,而默认的confirm()方法不允许任何更改,所以我利用了这个网站的资源和代码。我不确定将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源和jQuery,因为我是新手,但所有这些都不起作用。如何解决此问题?

试试这个:

$('#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"
});
});