我正在开发基于网络的 ERP,我需要一些帮助。
作为文本编辑器,我选择 CKEditor,效果很好,可以满足我的所有需求。 好吧……不完全是……
我添加了一个名为“wordcount”的插件,用于计算单词或字符并设置限制。
问题是我一个页面上有多个CKeditors,我需要为每个设置不同的限制。如您所见,该插件为两个编辑器设置了相同的限制:
参数通过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/