Javascript CK编辑。是否设置每页的最大字数?
有没有办法设置CK编辑器每页的最大字数 或者更好:每个编辑Javascript CK编辑。是否设置每页的最大字数?,javascript,ckeditor,Javascript,Ckeditor,有没有办法设置CK编辑器每页的最大字数 或者更好:每个编辑 我找不到这方面的任何文档。不要认为CKeditor是开箱即用的。试试看这里 或者 我在CKEditor文档中找到了解决方案;我已经用CKEditor 4.7.3对其进行了测试。请参阅url: 1) 创建config.js文件的副本(可能在同一位置,尽管示例显示的不同) 2) 添加您需要的任何设置,例如: 限制nb字符:“config.wordcount={maxCharCount:255,showWordCount:true,show
我找不到这方面的任何文档。不要认为CKeditor是开箱即用的。试试看这里 或者
我在CKEditor文档中找到了解决方案;我已经用CKEditor 4.7.3对其进行了测试。请参阅url: 1) 创建config.js文件的副本(可能在同一位置,尽管示例显示的不同) 2) 添加您需要的任何设置,例如: 限制nb字符:“config.wordcount={maxCharCount:255,showWordCount:true,showCharCount:true};” 或 限制nb字:“config.wordcount={maxWordCount:255,showWordCount:true,showCharCount:true};” 3) 在需要特定配置的页面中,将以下内容添加到调用CKEditor for textarea replacement的行中 例如:CKEDITOR.replace('editor1',{customConfig:'/custom/CKEDITOR_config.js'}) 4) 完成:-)可能需要在页面上刷新ctrl键才能重新加载新设置
请记住,您需要额外的插件来进行字数统计:htmlwriter、通知、撤消和字数统计。请参阅参考文档:下载CK编辑器,将其粘贴到Res文件夹中。 下载wordcount插件并将其粘贴到CKEditor的插件文件夹中 然后在config.cs(位于CKEditor文件夹中)中粘贴以下内容:
config.extraPlugins = 'wordcount';
config.wordcount = {
// Whether or not you want to show the Word Count
showWordCount: true,
// Whether or not you want to show the Char Count
showCharCount: false,
// Maximum allowed Word Count
maxWordCount: -1,
// Maximum allowed Char Count
maxCharCount: 10
};
然后在HTML中使用以下命令:
/* If instance is already present then destory it
*
*/
var currentEditor = CKEDITOR.instances.answerCKEditor;
if (currentEditor) {
currentEditor.destroy(true);
}
CKEDITOR.replace('answerCKEditor',{wordcount: {
showParagraphs: false,
showWordCount: true,
showCharCount: true,
countSpacesAsChars: false,
countHTML: false,
maxWordCount: -1,
maxCharCount: 40}
});
});
这将替换正常的文本区域:
<div class="form-group">
<label>Answer</label>
<textarea class="ckeditor" id="answerCKEditor" rows="6" cols="50" th:text="${faqDetail.answer}"></textarea>
</div>
答复
在CKEditor 4中,您可以编辑您的config.js
以限制字符和单词。您需要包括Wordcount插件
CKEDITOR.editorConfig = function( config ) {
// Include 'wordcount' plugin
config.extraPlugins = 'wordcount';
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: true,
// Whether or not you want to show the Char Count
showCharCount: true,
// Whether or not you want to count Spaces as Chars
countSpacesAsChars: false,
// Whether or not to include Html chars in the Char Count
countHTML: false,
// Whether or not to include Line Breaks in the Char Count
countLineBreaks: false,
// Maximum allowed Word Count, -1 is default for unlimited
// NOTE - This is where you configure Max Word Count
maxWordCount: -1,
// Maximum allowed Char Count, -1 is default for unlimited
maxCharCount: 250,
// Maximum allowed Paragraphs Count, -1 is default for unlimited
maxParagraphs: 1,
// How long to show the 'paste' warning, 0 is default for not auto-closing the notification
pasteWarningDuration: 0,
// Add filter to add or remove element before counting (see CKEDITOR.htmlParser.filter), Default value : null (no filter)
filter: new CKEDITOR.htmlParser.filter({
elements: {
div: function( element ) {
if(element.attributes.class == 'mediaembed') {
return false;
}
}
}
})
};
};
谢谢你的链接!