FCK判断内容是否为空(如果只是去空格,那么这种方式是错误的)(fifo什么时候为空,什么时候为满)快来看

随心笔谈2年前发布 admin
205 0 0

文章摘要

文章介绍了如何判断FCK编辑器内容是否为空,并提供了实现代码。主要内容包括: 1. 使用`FCKeditorAPI`获取编辑器实例 2. 检查内容长度,若为空则提示用户并返回`false` 3. `GetLength`函数计算文本长度,支持不同DOM结构 4. 实现了`String.prototype.trim`方法,用于去除前后空格 5. 文章通过代码示例展示了FCK编辑器内容判断的实现方式

//判断fck的内容是否为空

var oEditor=FCKeditorAPI.GetInstance(‘content’); //这里的content是FCK的ID值

if(GetLength(“content”)<=0) {

alert(‘内容不能为空!’);

oEditor.Focus();

return false;

}

function GetLength(str){

var oEditor=FCKeditorAPI.GetInstance(str) ;

var checkContent=oEditor.EditorDocument ;

var contentLength ;

if ( document.all ){

contentLength=checkContent.body.innerText.trim().length ;

}

else{

var r=checkContent.createRange() ;

r.selectNodeContents( checkContent.body ) ;

contentLength=r.toString().trim().length ;

}

return contentLength;

}

//去掉字符串的空格

String.prototype.trim=function()

{

return this.replace(/(^[\s]*)|([\s]*$)/g, “”);

}

© 版权声明

相关文章