首页 > 解决方案 > taggingJS 在输入时抛出错误。又名句号

问题描述

我将它用于标签:https ://github.com/sniperwolf/taggingJS/

下面的代码用于初始化 taaggingJS

var myOptions =
        {
            "no-duplicate": true,
            "no-duplicate-callback": null,
            "type-zone-class": "type-zone",
            "tag-box-class": "tagging",
            "forbidden-chars": ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "`", "~", "[", "]", "{", "}", "|", ";", ":", "'", "<", ">", ",", ".", "/", "?"],
            "forbidden-chars-callback": null
            // chars not included ", 
        };

$("#post_tags").tagging(myOptions);

每当我打字时。(句号)在 div 中,它响应错误说明

未捕获的 TypeError:b 不是 n.throwError 处的函数(tagging.min.js:1)

无法弄清楚为什么?任何人都可以帮助解决这个问题吗?

标签: javascriptjquerytagging

解决方案


禁止字符回调是配置参数,它决定在发现禁止字符时要做什么。该参数的默认值为“window.alert”,这就是在输入禁止字符时出现警报的原因。

禁止字符回调需要一个函数,其中您已将“null”传递给它,这就是抛出错误的原因。

现在,根据您的要求,不需要显示警报并且不显示此类错误。您可以传递一个匿名函数,它不会避免 javascript 错误。

看看 JS 代码

var myOptions = {
    "no-duplicate": true,
    "no-duplicate-callback": null,
    "type-zone-class": "type-zone",
    "tag-box-class": "tagging",
    "forbidden-chars": ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "`", "~", "[", "]", "{", "}", "|", ";", ":", "'", "<", ">", ",", ".", "/", "?"],
    "forbidden-chars-callback": function(){}
};

$("#post_tags").tagging(myOptions);  

可用规范的完整列表:
https ://github.com/sniperwolf/taggingJS/#available-options

要查看完整的 JS 文件,请访问 url:
https ://cdn.rawgit.com/sniperwolf/taggingJS/master/tagging.js

在此处输入图像描述


推荐阅读