`
yjshengshe
  • 浏览: 201947 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

用js给fckeditor赋值、取值的办法

 
阅读更多
方法正确,可以使用!
‍ //获取编辑器中HTML内容
function getEditorHTMLContents(EditorName)
{
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.GetXHTML(true));
}
//获取编辑器中文字内容
function getEditorTextContents(EditorName)
{
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.EditorDocument.body.innerText);
}
//设置编辑器中内容
function SetEditorContents(EditorName, ContentStr)
{
var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
oEditor.SetHTML(ContentStr) ;
}
赋值:
Java代码
var oEditor = FCKeditorAPI.GetInstance('ncontent');  
oEditor.SetHTML(“三菱电机法拉撕开对方”);

还有一个使用的是jquery来实现
jQuery FCKEditor插件取值、赋值
2008-12-13 16:51
第一步:导入需要的js文件(根据实际情况修改相应路径)
Java代码
<script src="../js/jquery.js" type=text/javascript></script>  
<script src="../js/jquery.FCKEditor.js" type=text/javascript></script>  
<script src="../fckeditor/fckeditor.js" type="text/javascript"></script>
<script src="../js/jquery.js" type=text/javascript></script>
<script src="../js/jquery.FCKEditor.js" type=text/javascript></script>
<script src="../fckeditor/fckeditor.js" type="text/javascript"></script>

第二步:初始化(根据实际情况修改相应路径)
Java代码
//初始化FCKEditor  
    $.fck.config = {path: '/这里是你的项目名称/fckeditor/', height: 400 ,toolbar:'Default'};  
    $('textarea#ncontent').fck();
//初始化FCKEditor
    $.fck.config = {path: '/这里是你的项目名称/fckeditor/', height: 400 ,toolbar:'Default'};
    $('textarea#ncontent').fck();

其中#ncontent为页面你所绑定的textArea的id或name
第三步:取值
Java代码
var getcontent = $.fck.content('ncontent', ''); //其中ncontent为页面你所绑定的textarea的id或name
var getcontent = $.fck.content('ncontent', ''); //其中ncontent为页面你所绑定的textarea的id或name

第四步:赋值(更新的时候先把原有的值赋给textarea)
Java代码
var oEditor = FCKeditorAPI.GetInstance('ncontent');  
oEditor.SetHTML(data.news_add.na_newscontent);
http://hi.baidu.com/cicon/blog/item/37a42097b2dbdb7d55fb9684.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics