当前位置: 移动技术网 > IT编程>开发语言>Java > AJAX FCKEditor Rich Editor整合篇第1/2页

AJAX FCKEditor Rich Editor整合篇第1/2页

2017年12月12日  | 移动技术网IT编程  | 我要评论
(http://www.fckeditor.net, javaeye的编辑器也是采用的fckeditor,xx所见略同?呵呵),它opensource(免费啊,可以直接改源

真正更新处理代码如下:
复制代码 代码如下:

fck.updatelinkedfield = function () {
fck.linkedfield.value = fck.getxhtml(fckconfig.formatoutput); // 将fckeditor编辑的内容取出来,这里是我们关心的重点
fck.events.fireevent("onafterlinkedfieldupdate");
};

ok,大致过程我们基本上已经了解了,至于fckeditor是如何在执行onsubmit之前执行绑定的更新处理的,暂且不表。

不过这里对fckeditor的几个对象类需要了解一下,一个是fckconfig(保存一些相关的配置信息),fck(取编辑器中编辑的内容需要用到的)。这些类都存活在编辑器所在的iframe页面之中,在linkedfield所在的页面是无法访问到的。

下面是我们的使用代码,这里是通过js创建fckeditor实例的方式。
首先定义一个全局的fckeditor对象: 
复制代码 代码如下:

var ofckeditor = null;
var ofckeditor = null;

在页面初始化之后(一般是在body的onload事件中完成)创建ofckeditor对象
复制代码 代码如下:

ofckeditor = new fckeditor( 'frmentity_editor_content'/*linkedfield元素id*/, '100%;','400px', 'default') ;
ofckeditor.basepath = "${request.getcontextpath()}/editor/" ;
ofckeditor.replacetextarea() ;

ofckeditor = new fckeditor( 'frmentity_editor_content'/*linkedfield元素id*/, '100%;','400px', 'default') ;
ofckeditor.basepath = "${request.getcontextpath()}/editor/" ;
ofckeditor.replacetextarea() ;

接下来是在执行ajax请求提交前的处理: 
复制代码 代码如下:

var inputelementid = "frmentity_editor_content"; // linkedfield元素id
var frameelement = eval(inputelementid + "___frame"); // 用来嵌入fckeditor的iframe的id
var inputelement = eval(inputelementid);
inputelement.value = frameelement.window.fck.getxhtml(frameelement.window.fckconfig.formatoutput); // 取得fckeditor中的内容同步到linkedfield中去
// 收集提交内容,执行ajax请求
....

var inputelementid = "frmentity_editor_content"; // linkedfield元素id
var frameelement = eval(inputelementid + "___frame"); // 用来嵌入fckeditor的iframe的id
var inputelement = eval(inputelementid);
inputelement.value = frameelement.window.fck.getxhtml(frameelement.window.fckconfig.formatoutput); // 取得fckeditor中的内容同步到linkedfield中去
// 收集提交内容,执行ajax请求
....


这个就是我的整合过程,其实还是挺简单的,不过碰到一个问题,就是在打开页面之后,输入焦点总是停留在fckeditor的编辑区里面,而fckeditor自己提供的例子里面不会出现这个情况,写法也没有什么区别,不知道问题出在哪里,有知道原因的朋友告知一声。
2

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网