Content

使用Js获取、插入和更改FCKeditor编辑器里的内容(javascript获取元素值)居然可以这样

文章摘要

本文主要讨论了富文本编辑器(FCK editor)的相关功能,重点介绍了几个关键函数的作用机制。首先,文章介绍了`insertHTMLToEditor`函数,用于向编辑器插入HTML代码;接着,`getEditorHTMLContents`和`getEditorTextContents`两个函数分别用于获取编辑器中的HTML内容和文字内容;此外,`SetEditorContents`函数用于设置编辑器中的内容,`getLength`函数用于统计内容字数,`ExecuteCommand`函数用于执行特定操作。这些函数共同作用于富文本编辑器的管理与操作,为编辑器的自动化控制提供了基础实现。

 //向编辑器插入指定代码 function insertHTMLToEditor(codeStr){ var oEditor=FCKeditorAPI.GetInstance(“content”); oEditor.InsertHtml(codeStr); // “html”为HTML文本 } //获取编辑器中HTML内容 function getEditorHTMLContents() { var oEditor=FCKeditorAPI.GetInstance(“content”); return(oEditor.GetXHTML(false)); } // 获取编辑器中文字内容 function getEditorTextContents() { var oEditor=FCKeditorAPI.GetInstance(“content”); return(oEditor.EditorDocument.body.innerText); } // 设置编辑器中内容 function SetEditorContents(ContentStr) { var oEditor=FCKeditorAPI.GetInstance(“content”) ; oEditor.SetHTML(ContentStr) ; } //向编辑器插入指定代码 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() ; }