免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 889 | 回复: 0
打印 上一主题 下一主题

fckeditor用javascript创建 [复制链接]

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-13 20:54 |只看该作者 |倒序浏览

首先介绍如何用javascript创建fckeditor
//--------------------------------------------------------------------------------------------------
第一在头部有个引用:
CODE:
<script type="text/javascript" src="/FCKeditor/fckeditor.js"></script> 加入创建代码(创建的代码有多种形式)
第一种创建模式: 直接创建

CODE:
<script type="text/javascript">
var oFCKeditor = new FCKeditor('FCKeditor1');
oFCKeditor.BasePath = "/FCKeditor/";
oFCKeditor.Create();
</script> 第二种创建模式: 替换textarea
CODE:
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor( 'MyTextarea' ) ;
oFCKeditor.BasePath = "/FCKeditor/" ;
oFCKeditor.ReplaceTextarea() ;
}
</script>
<textarea id="MyTextarea" name="MyTextarea">This is <b>the</b> initial value.</textarea>在对于替换多个textArea时可以使用如下方法
CODE:
<html>
<head>
<title>Testing ReplaceAll()</title>
<script type="text/javascript" src="/FCKeditor/fckeditor.js"></script>
<script type="text/javascript">
<!--
function ReplaceAllTextareas() {
// replace all of the textareas
var allTextAreas = document.getElementsByTagName("textarea");
for (var i=0; i < allTextAreas.length; i++) {
var oFCKeditor = new FCKeditor( allTextAreas.name ) ;
oFCKeditor.BasePath = "/FCKeditor/" ;
oFCKeditor.ReplaceTextarea() ;
}
}
// -->
</script>
</head>
<body >
<form>
<input type="checkbox" name="bobby" /> bobby <br />
<input type="checkbox" name="sue" /> sue <br />
Summary:
<textarea name="summary" rows="4" cols="80"> here is the summary </textarea>
Overview:
<textarea name="overview" rows="10" cols="80"> here is the overview </textarea>
Detials:
<textarea name="details" rows="60" cols="80"> here are teh details </textarea>
<input type="submit" name="sue" /> <br />
<input />
</form>
</body>
</html> 方法说明:
oFCKeditor.Width = 400 ; // 400 pixels
oFCKeditor.Width = "80%" ; // 80 percent
oFCKeditor.Height = 400 ; // 400 pixels
oFCKeditor.ToolbarSet = "MyToolbar" ;
oFCKeditor.Value = "<h1>Testing</h1>This is a <b>sample</b>." ;
oFCKeditor.BasePath = "/Components/FCKeditor/" ;
oFCKeditor.CheckBrowser = true ; //检查浏览器兼容性
oFCKeditor.DisplayErrors = false ; //转义editor显示错误信息
结合ajax使用fckeditor
//--------------------------------------------------------------------------------------------------
应用于ajax的时候可以考虑通过自带的例子sample08.html里面的函数GetContents结合使用
CODE:
function GetContents(fck)
{
        // Get the editor instance that we want to interact with.
        var oEditor = FCKeditorAPI.GetInstance(fck) ;
        // Get the editor contents in XHTML.
        return oEditor.GetXHTML( true )  ;                // "true" 表示执行格式化
}url处理:
CODE:
fckeditor_value="fckeditor_value="+encodeURIComponent(GetContents("MyFCKeditor"))?//通过encodeURIComponent的javascript函数处理掉传参数里面出现各种不符字符
获取fckeditor里面的参数
提交:(这里使用的是prototype)

CODE:
new Ajax.Request("magsee.php",{method: 'post',parameters:fckeditor_value,onComplete:success_vote});结果的获取magsee.php
CODE:
$_POST['fckeditor_value']


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4206/showart_529877.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP