Content

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

文章摘要

这篇文章的内容是关于检查富文本编辑器(FCK)编辑区域的文本是否为空,并计算文本的长度。代码中使用`FCKeditorAPI`获取编辑器实例,并通过`GetLength`函数判断文本长度。如果文本为空,会显示"内容不能为空!"并焦点到编辑器。此外,代码还定义了一个`trim`方法,用于去除字符串两端的空格。文章的核心内容是围绕文本内容的有效性检查和字符串格式处理展开。

//判断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, “”);

}