文章摘要
这篇文章介绍了一个使用FCKeditor API的脚本,可以在HTML编辑器中实现字符长度限制的功能。通过绑定`OnSelectionChange`事件,当用户输入超过3个字符时,会显示提示信息并阻止输入,达到上限时显示“字符数达到上限”的提示信息。该脚本通过获取编辑内容的文本长度,并根据设定的`maxLength`值动态调整提示信息。文章重点介绍了如何限制字符输入,并突出显示了关键词:`function`、`FCKeditor`、`OnSelectionChange`、`editor`、`maxLength`、`content`、`len`、`maxLength`、`text`、`info`、`len < maxLength`、`len > maxLength`。
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()
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。