当幸福来敲门

我就会牢牢抓住!
随笔 - 50, 文章 - 3, 评论 - 8, 引用 - 0
数据加载中……

FCKeditor 取值

《转自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>


posted on 2013-07-31 14:19 wyx 阅读(170) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: