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

随心笔谈11个月前发布 admin
97 0

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

}

© 版权声明

相关文章