接下来呢,就讲一下如何创建自己的在线编辑器,这里以ASP和JS版的为例,ASP版示例代码,一般用于后台操作:
| <% Dim oFCKeditor Set oFCKeditor = New FCKeditor oFCKeditor.BasePath = "/" oFCKeditor.ToolbarSet = "Default" oFCKeditor.Width = "100%" oFCKeditor.Height = "400" oFCKeditor.Value = rs("logbody") oFCKeditor.Create "logbody" %> |
<%
Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = "/"
oFCKeditor.ToolbarSet = "Default"
oFCKeditor.Width = "100%"
oFCKeditor.Height = "400"
oFCKeditor.Value = rs("logbody")
oFCKeditor.Create "logbody"
%>
ASP版的,当然只能用在以.asp为扩展名的页面中,如果你在前在fckedito.asp里设置过BasePath为"/"的话,这里就可以省掉第三行,ASP版的只有一个Create函数。建议在修改一篇内容时用ASP版的。
接下来看JS版的:
| <script type="text/javascript"> var oFCKeditor = new FCKeditor( 'logbody' ) ; oFCKeditor.BasePath = '/' ; oFCKeditor.ToolbarSet = 'Basic' ; oFCKeditor.Width = '100%' ; oFCKeditor.Height = '400' ; oFCKeditor.Value = '' ; oFCKeditor.Create() ; </script> |
BasePath的设置同上所述,JS版的可用于任何网页中,甚至用于html页面,因为其是客户端生成的,这样的好处就是一可以减小网络流量,因为编辑器文件只需下载一次,二是可以由客户端定义什么时候显示,由于fckeditor初始化需要一定时间,在这一点上JS就很有作用了。
另外,JS版的还有一个功能函数就是ReplaceTextarea()函数,可以替换指定的TextArea,拿我的网站的日志的回复部分示例:
| <script type="text/javascript"> <!-- function showFCK(){ var oFCKeditor = new FCKeditor( 'fbContent' ) ; oFCKeditor.BasePath = '/' ; oFCKeditor.ToolbarSet = 'Basic' ; oFCKeditor.Width = '100%' ; oFCKeditor.Height = '200' ; oFCKeditor.Value = '' ; //oFCKeditor.Create() ; oFCKeditor.ReplaceTextarea() ; //document.blog_feedback.blogsubmit.disabled = ''; document.blog_feedback.blogsubmit.style.display = ''; document.blog_feedback.openFCK.disabled = 'true'; document.blog_feedback.openFCK.style.display = 'none'; } //--> </script> |
把其写成一个简单的函数,当用户显示打开编辑器时才生成这个fckeditor,不用每次刷新页面都去初始化一个编辑器,页面的速度就会快多了。
补遗:前面讲到了,说是在编辑已有数据内容时不要用JS版的,那是因为单引号(')的问题造成的,在数据内容里难免会有单引号存在而用JS版生成编辑器时可能就会因为单引号问题,而使编辑器无法正常生成,而采用asp则不同,用ASP版本的是因为数据被当成是一个变量了,然后直接赋值给编辑器域。还有就是除非你要用ReplaceTextArea()方法来生成编辑器,否则你不需先写一个<textarea>这样的标签,一切都会由fckeditor自动生成的,你所需做的只是给fckeditor指定一个实例名。同时你也不用担心如何提交,在表单提交的时候,fckeditor会自动提交,提交的变量名是以你指定的fckeditor实例命名的。
fckeditor最新版本是2.3.1,下载地址:http://www.fckeditor.net/download
关注此文的读者还看过: