javascript - CKEditor - 在一个页面中限制多个编辑器的字符

标签 javascript ckeditor ckeditor4.x ckeditor-wordcount

我正在开发基于网络的 ERP,我需要一些帮助。

作为文本编辑器,我选择 CKEditor,效果很好,可以满足我的所有需求。 好吧……不完全是……

我添加了一个名为“wordcount”的插件,用于计算单词或字符并设置限制。

问题是我一个页面上有多个CKeditors,我需要为每个设置不同的限制。如您所见,该插件为两个编辑器设置了相同的限制:

enter image description here

参数通过config.js传递:

config.wordcount = {

// Whether or not you want to show the Paragraphs Count
showParagraphs: false,

// Whether or not you want to show the Word Count
showWordCount: false,

// Whether or not you want to show the Char Count
showCharCount: true,

// Whether or not you want to count Spaces as Chars
countSpacesAsChars: true,

// Whether or not to include Html chars in the Char Count
countHTML: false,

// Maximum allowed Word Count, -1 is default for unlimited
maxWordCount: 400,

// Maximum allowed Char Count, -1 is default for unlimited
maxCharCount: 400};

你知道一些方法吗? 也可以使用另一个插件或“手动”。

提前致谢!

最佳答案

我是这样实现的:需要用maxWord和maxChar向textArea标签添加attrs数据,初始化CKeditor

window.InitializeCkeditor = {
  init: function() {
    var element, elements, i, results;
    elements = CKEDITOR.document.find('.js-ckeditor'); // your textArea
    i = 0;
    results = [];
     while (element = elements.getItem(i++)) {
       CKEDITOR.replace(element, {
         toolbar: 'mini', // your toolbar 
         height: 200
       });
       results.push(CKEDITOR.on('instanceCreated', function(event) {
         var editor, element;
         editor = event.editor;
         element = editor.element;
         return editor.on('configLoaded', function() {
           return editor.config.wordcount = {
             showWordCount: true,
             maxWordCount: element.data('word-max')
           };
        });
      }));
    }
    return results;
  }
};

关于javascript - CKEditor - 在一个页面中限制多个编辑器的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34473418/

相关文章:

javascript - CKEditor 图标路径不是 URLEncoded

Javascript + Firebase 博客 addpost 函数firstId 返回未定义

javascript - React Js-无法将 html 标签内的 prop 值视为键

ruby-on-rails - 回形针,CKEditor validates_attachment_content_type 错误

php - 从 ms word 复制和粘贴后,ckeditor 格式看起来不太好

html - ckeditor 字体样式 13 px

javascript - 为什么 instanceof 在 Chrome、Safari 和 Edge 上返回 false,而在 FireFox 上返回 true?

javascript - CKEditor 在样式中插入不可编辑的 HTML

javascript - 使用不带选项值的 Excel VBA 设置 javascript 输入值

Javascript正则表达式,匹配长度限制之前的所有单词