復制代碼代碼如下:
//判斷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, "");
}