Content

Fckeditor编辑器内容长度限制统计实现方法(fckeditor编辑器去掉单元格项)一篇读懂

文章摘要

这篇代码为Typora文本编辑器设置了一个字符限制功能。通过FCKeditorAPI获取编辑器实例,并绑定OnSelectionChange事件,当用户输入超过3个字符时,系统会提示减少字符数量。代码通过获取当前内容长度,判断是否达到限制,并动态显示提示信息,以防止内容过于冗长。

window.onload=function(){

function FCKeditor_OnComplete()

{

var editor=FCKeditorAPI.GetInstance(‘info’) ;

editor.Events.AttachEvent(‘OnSelectionChange’, editor_keydown);

}

function editor_keydown(editor)

{

var maxLength=3; //最大输入字数

content=$(editor.EditorDocument.body).text();

var len=content.length;

var $info=$(‘#info’);//存放提示信息

if(len < maxLength){

.text(“还可以输入 “+(maxLength-len)+”字”);

}

if(len==maxLength){

$info.text(“字数达到上限”);

}

if(len > maxLength){

$info.text(” 输入字符超过”+maxLength+”个,请更改!”);

}

}

FCKeditor_OnComplete()

}