javascript - 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)
无法弄清楚为什么?任何人都可以帮助解决这个问题吗?
解决方案
禁止字符回调是配置参数,它决定在发现禁止字符时要做什么。该参数的默认值为“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
推荐阅读
- javascript - 承诺代码审查
- html - 从网站中删除 .html 扩展名
- android - 执行 adb-sync 后,文件 * 真的 * 存在于哪里?
- angular - 将属性公开为可观察对象的最简单语法?
- excel - 如何在 Excel 中编写 Countifs 公式?
- ruby-on-rails - Cancancan ActiveAdmin:跳过对 :create 的授权
- swift - 在 Swift 中继承 NSLayoutConstraint
- r - 在 Shiny 中,我只想在 UI 加载期间更新选择输入()一次
- java - 未找到名称为“默认”的配置 gradle 同步失败
- apache-zeppelin - 在 Windows 10 或 7 的 Apache Zeppelin 中运行 spark 程序时出错