发布于2026-07-22 阅读(0)
扫一扫,手机访问
先看最简单的编辑器代码,这个代码段相信多数开发者都见过,核心逻辑其实非常直接。
接下来是检测字数的功能,需要借助FCKeditorAPI来实现,代码也很直白:
function checklength()
{
var Content;
var oEditor = FCKeditorAPI.GetInstance('Content') ;
Content=oEditor.GetXHTML(true)
alert("n当前: "+Content.length+" 个字符");
return false;
}
再看一个实际限制编辑器内容长度的例子,通过监听OnSelectionChange事件,实时提醒用户输入情况:
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()
}
以上代码覆盖了FCKeditor的基本调用、字数检测以及长度限制,是实际开发中很实用的几个片段。
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
8