FCKeditor 客戶端取值和客戶端驗證問題

content相當於你例子中的FCKeditor1。

//獲取格式化的編輯器內容
function getEditorContents(){
   var oEditor = FCKeditorAPI.GetInstance("content");
   alert(oEditor.GetXHTML(true));
}
//向編輯器插入指定代碼
function insertHTMLToEditor(codeStr){
   var oEditor = FCKeditorAPI.GetInstance("content");
   if (oEditor.EditMode==FCK_EDITMODE_WYSIWYG){
oEditor.InsertHtml(codeStr);
   }else{
return false;
   }
}
//統計編輯器中內容的字數
function getLength(){
   var oEditor = FCKeditorAPI.GetInstance("content");
   var oDOM = oEditor.EditorDocument;
   var iLength ;
   if(document.all){
iLength = oDOM.body.innerText.length;
   }else{
var r = oDOM.createRange();
r.selectNodeContents(oDOM.body);
iLength = r.toString().length;
   }
   alert(iLength);
}
//執行指定動作
function ExecuteCommand(commandName){
   var oEditor = FCKeditorAPI.GetInstance("content") ;
   oEditor.Commands.GetCommand(commandName).Execute() ;
}
//設置編輯器中內容
function SetContents(codeStr){
   var oEditor = FCKeditorAPI.GetInstance("content") ;
   oEditor.SetHTML(codeStr) ;
}

===========================================================================

用的RequiredFieldValidator來驗證Fckeditor的內容是否爲空,結果添加的時候發現第一次提交他會提示爲空,要再點一次才能提交。

下面是解決方法:
<script language="javascript"   type="text/javascript">
var oEditer;
function CustomValidate(source, arguments)
{
     var value = oEditer.GetXHTML(true);
     if(value=="")
     {
       arguments.IsValid = false;
     }
    else
    {
        arguments.IsValid = true;
     }
}

function FCKeditor_OnComplete( editorInstance )
{
     oEditer = editorInstance;
}
</script>

把上面的腳本添加至頁面內,然後選用CustomValidator驗證控件,設置ClientValidationFunction="CustomValidate",並設置ValidateEmptyText屬性爲True,還有記得設置ControlToValidate啊。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章