《转自
http://blog.sina.com.cn/s/blog_5f66526e0100kf6b.html》
主要步骤:
第一步:导入需要的js文件(根据实际情况修改相应路径)
<script src="js/jquery.js" type=text/javascript></script>
<script src="fckeditor/fckeditor.js" type="text/javascript"></script>
第二步:初始化(根据实际情况修改相应路径)
sBasePath = '/duotunkf/fckeditor/' ;#编辑器所在文件夹;
oFCKeditor = new FCKeditor('content') ;
oFCKeditor.BasePath = sBasePath ;
oFCKeditor.Value = 'test' ;
oFCKeditor.ToolbarSet = 'Basic' ;
oFCKeditor.Create() ;
其中content为页面你所绑定的textArea的id或name
第三步:取值
var oEditor = FCKeditorAPI.GetInstance('content');
editorValue = oEditor.GetHTML();
第四步:赋值(更新的时候先把原有的值赋给textarea)
var oEditor = FCKeditorAPI.GetInstance('content');
oEditor.SetHTML("value");
下面是本人写的一个赋值测试程序,供大家参考。源码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.3.2.min.js"></script>
<script src="fckeditor/fckeditor.js"></script>
<script>
$(document).ready(function(){
$("#test").click(function(){
var oEditor = FCKeditorAPI.GetInstance('content');
oEditor.SetHTML($("#test option:selected" ).text());
});
});
</script>
</head>
<body>
<form action="" method="post">
<script>
sBasePath = '/duotunkf/fckeditor/' ;#编辑器所在文件夹;
oFCKeditor = new FCKeditor('content') ;
oFCKeditor.BasePath = sBasePath ;
oFCKeditor.Value = 'test' ;
oFCKeditor.ToolbarSet = 'Basic' ;
oFCKeditor.Create() ;
</script>
<br>
<label for="test">
<select name="test" size="4" id="test">
<option value="1">i.点击这里改变编辑器的值</option>
<option value="2">ii.点击这里改变编辑器的值</option>
<option value="3">iii.点击这里改变编辑器的值</option>
</select>
</label>
</form>
</body>
</html>