Noty 中的 JavaScript 插件会给出错误

Javascript plug in Noty gives error

本文关键字:出错 错误 插件 中的 JavaScript Noty      更新时间:2023-09-26

我有以下JavaScript代码:

function delete_draft(id, name) {
    var text = 'Are you sure you want to delete "' + name + '"?';
    alert(id + name)
    var noty = noty({
        text: text,
        buttons: [
        {addClass: 'btn btn-primary', text: 'Yes', onClick: function($noty) {
            // this = button element
            // $noty = $noty element
            $noty.close();
            $.post('/ajax/drafts/delete', {id:id}, function(data) {
                document.location.reload(true);
            });
        }
        },
        {addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
            $noty.close();
        }
        }
    ]});
}

当我从领事delete_draft(6, "this is it")运行时,我收到此错误

TypeError: undefined is not a function
arguments: Array[1]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "called_non_callable"
__proto__: Error

我该如何解决这个问题?Noty的网站是 http://needim.github.com/noty/如果您认为它应该有效,请发表评论。

我刚刚遇到了这个问题。原来是因为变量名noty与导出的函数名noty相同。

var n = noty({text: 'testing 123'});

只需更改变量名称即可为我修复它。

除了重命名变量之外,请确保包含布局 js 文件。默认值为 top,因此如果未在选项中指定,则需要包含 noty/layouts/top.js 。如果指定任何其他布局,请包括相应的布局 js 文件。

相关文章: