您的位置:首页 > Web前端 > JavaScript

FCKEDITOR的JAVASCRIPT创建和使用方法

2011-04-28 17:59 405 查看
JAVASCRIPT方式引用FCKEDITOR简单方便,通过以下两个步骤就可以实现:

1、在<HEAD></HEAD>里面插入下面这段代码

<mce:script type="text/javascript" src="/FCKeditor/fckeditor.js" mce_src="FCKeditor/fckeditor.js"></mce:script>


2、在需要显示录入框的地方加上下面这段代码

<mce:script type="text/javascript"><!--
var oFCKeditor = new FCKeditor('FCKeditor1');
oFCKeditor.BasePath = "/FCKeditor/";
oFCKeditor.Create();
// --></mce:script>


,当然不是任何地方都可以,必须在<Form></Form>里面才行。

通过这两个步骤就可以在你的网站里用FCKEditor来做录入了,Form提交以后通过Request("FCKEditor1")就可以提取出FCKEditor里面录入的东西,如果要把东西写到FCKEditor里面去其实也很简单,直接给oFCKEditor.Value属性赋值就可以,例如下面这种形式:

<mce:script type="text/javascript"><!--
var oFCKeditor = new FCKeditor('FCKeditor1');
oFCKeditor.BasePath = "/FCKeditor/";
oFCKeditor.Value = '<p>This is some <strong>sample text<//strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor<//a>.<//p>';
oFCKeditor.Create();
// --></mce:script>


但是有一点是需要注意的,在给oFCKeditor.Value赋值的时候有的字符是必须转义以后才能赋给oFCKeditor.Value,如果不转义直接赋值的话会照成FCKEDITOR出错无法使用的,这些字符主要包括了单引号、回车、换行、斜杠,解决方法就是提前对这些字符进行处理,处理完了以后再赋值就没问题了,比如:

<%
dim tmpString
tmpString="……"        '省略取值
tmpString=replace(tmpString,"'","/'")
tmpString=replace(tmpString,"/","//")
tmpString=replace(tmpString,vbcrlf,"")
tmpString=replace(tmpString,vbcr,"")
tmpString=replace(tmpString,vblf,"")
%>
<mce:script type="text/javascript"><!--
var oFCKeditor = new FCKeditor('FCKeditor1');
oFCKeditor.BasePath = "/FCKeditor/";
oFCKeditor.Value = '<%=tmpString%>';
oFCKeditor.Create();
// --></mce:script>


当然这是ASP的写法,其他技术基本也都大同小异
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐