前几天用了下,其实就是里面的_sample里面的例子。
一、创建fckeditor
<div style="display:none" id="content">页面Load时,不显示编辑器
<script type="text/javascript">
<!--
oFCKeditor.BasePath = '/fckeditor/' ; // '/fckeditor/' is the default value.
var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
oFCKeditor.BasePath = sBasePath ;
//假设fckeditor文件夹在根目录下,而当前页在根目录下的temp文件夹下,则sBasePath="../fckeditor/"
oFCKeditor.Width=542;
oFCKeditor.Height = 242;
oFCKeditor.ToolbarSet = "default" ;
//根据不同的角色,显示不同的工具条.通常是在服务器上写一个关于用户类型的cookie,用javascript读取cookie,然后在此设置工具条的显示
oFCKeditor.Value = ' <p><a href="http://www.goberl.com/">Goberl<\/a>.<\/p>' ;
oFCKeditor.Create() ;
//-->
</script>
二、在创建成功时才做一些操作
特别注意:不要在FCKeditor的OnComplete之前,对FCKeditor进行任何操作,比如清除里面的默认值——页面加载FCKeditor需要一定时间
function FCKeditor_OnComplete( editorInstance )
{
document.getElementById('content').style.display = 'block' ;
}
三、插入HTML
请注意创建时的FCKeditor1与GetInstance()函数传入的值的对应
function InsertHTML()
{
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Check the active editing mode.
if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
{
oEditor.InsertHtml( '- <b>My Name Is Goberl<\/b> -' ) ;
}
else
alert( 'You must be on WYSIWYG mode!' ) ;
}
四、修改oFCKeditor HTML
function SetContents()
{
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
var value="把编辑器里面的内容给替换掉";
oEditor.SetData(value);
}
五、获取oFCKeditor的HTML
注意:请不要试图用oFCKeditor.Value 获取里面的HTML
function GetContents()
{
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1')) ;
var strHTML=oEditor.GetXHTML( true );
return strHTML;
}
以上5点已经能满足基本操作了。