CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入圖片)
更新時間:2010年03月20日 20:09:37 作者:
CKEditor 是著名的 HTML 編輯器,IBM、Oracle、Adobe 等都在用。CKEditor 創(chuàng)建于 2003 年,其前身為 FCKEditor,在 2009 年的時候把“F”去掉了,更名為 CKEditor。
其開源協(xié)議是基于 GPL, LGPL 和 MPL 的。官方網(wǎng)站:http://ckeditor.com/
一般來說,我們在編輯內(nèi)容時,先是讀入到 textarea,再將 textarea 的內(nèi)容賦給編輯器。因為直接把內(nèi)容作為字符串給編輯器的 Value 屬性賦值使用的是 JavaScript 代碼,要讓 JS 代碼不受內(nèi)容中雙引號、換行等的干擾,只有先讀入到 textarea 最方便。
使用 FCKeditor 2.6.5
<div><textarea id="fckcontent" name="content">cftea</textarea></div>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
<!--
var oFCKeditor = new FCKeditor("fckcontent");
oFCKeditor.BasePath = "fckeditor/"; // fckeditor 文件夾位置。
oFCKeditor.Create();
//-->
</script>
本來應(yīng)該用 display:none 將 textarea 隱藏起來,不過為了查看效果,這里不隱藏。
這樣編輯器就自動與 fckcontent 關(guān)聯(lián)起來了,打開網(wǎng)頁時 FCKeditor 自動讀取 textarea 的內(nèi)容,提交時又自動將其內(nèi)容(自動為 XHTML)賦給 textarea。
注意,我們 textarea 的 id 和 name 值不一樣,為什么呢?
這里應(yīng)該是這個版本不太完善的地方,如果我們把 textarea 的 id 和 name 值設(shè)置為一樣,那么 FCKeditor 文本區(qū)的 name 值也是 content,在服務(wù)器端 Request.Form("content").Count 就會有兩個,我們服務(wù)器端取值就稍稍有點不方便,得用 Request.Form("content")(0)。如果我們將 id 設(shè)為 fckcontent,那么 FCKeditor 文本區(qū)的 name 就是 fckcontent,與 textarea 不同名。
設(shè)置編輯器寬高
var oFCKeditor = new FCKeditor("fckcontent", 500, 300);
或
var oFCKeditor = new FCKeditor("fckcontent");
oFCKeditor.Width = 500;
oFCKeditor.Height = 300;
設(shè)置工具條
var oFCKeditor = new FCKeditor("fckcontent", 500, 300, "Basic");
注意第四個參數(shù),其可選值有 Basic、Default,注意大小寫不可搞錯,分別表示基本工具條、默認(rèn)工具條(全部按鈕)。
設(shè)置初始值、設(shè)置值、取值
設(shè)置初始值
實際上設(shè)置初始值很少用,因為一般都是與 textarea 關(guān)聯(lián)的,故只是簡單列出來一下,不深究。說明一下,如果關(guān)聯(lián)的 textarea 存在,則賦初始值是沒有用的。
var oFCKeditor = new FCKeditor("fckcontent2", 500, 300, "Default", "腳本之家");
或
var oFCKeditor = new FCKeditor("fckcontent2", 500, 300, "Default");
oFCKeditor.BasePath = "fckeditor/";
oFCKeditor.Value = "cftea"; // 必須在 Create 之前
oFCKeditor.Create();
設(shè)置值
若要演示此示例,最好是放在按鈕的事件處理程序中,目的是有些延遲,否則會說 FCKeditorAPI 未定義。
var oEditor = FCKeditorAPI.GetInstance("fckcontent");
oEditor.SetHTML("腳本之家");
取值
若要演示此示例,最好是放在按鈕的事件處理程序中,目的是有些延遲,否則會說 FCKeditorAPI 未定義。
var oEditor = FCKeditorAPI.GetInstance("fckcontent");
alert(oEditor.GetXHTML()); // 還有個類似方法是 GetHTML,但不推薦用 GetHTML。
您這樣做很危險:
var oEditor = FCKeditorAPI.GetInstance("fckcontent");
oEditor.SetHTML("腳本之家");
alert(oEditor.GetXHTML()); // 這里的值并不一定是上一句賦的值。因為他們太近了,值還沒來得及賦,就已經(jīng) alert 了。
插入圖片
若要演示此示例,最好是放在按鈕的事件處理程序中,目的是有些延遲,否則會說 FCKeditorAPI 未定義。
FCKeditorAPI.GetInstance("fckcontent").InsertHtml("<img src...>");
一般來說,我們在編輯內(nèi)容時,先是讀入到 textarea,再將 textarea 的內(nèi)容賦給編輯器。因為直接把內(nèi)容作為字符串給編輯器的 Value 屬性賦值使用的是 JavaScript 代碼,要讓 JS 代碼不受內(nèi)容中雙引號、換行等的干擾,只有先讀入到 textarea 最方便。
使用 FCKeditor 2.6.5
復(fù)制代碼 代碼如下:
<div><textarea id="fckcontent" name="content">cftea</textarea></div>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
<!--
var oFCKeditor = new FCKeditor("fckcontent");
oFCKeditor.BasePath = "fckeditor/"; // fckeditor 文件夾位置。
oFCKeditor.Create();
//-->
</script>
本來應(yīng)該用 display:none 將 textarea 隱藏起來,不過為了查看效果,這里不隱藏。
這樣編輯器就自動與 fckcontent 關(guān)聯(lián)起來了,打開網(wǎng)頁時 FCKeditor 自動讀取 textarea 的內(nèi)容,提交時又自動將其內(nèi)容(自動為 XHTML)賦給 textarea。
注意,我們 textarea 的 id 和 name 值不一樣,為什么呢?
這里應(yīng)該是這個版本不太完善的地方,如果我們把 textarea 的 id 和 name 值設(shè)置為一樣,那么 FCKeditor 文本區(qū)的 name 值也是 content,在服務(wù)器端 Request.Form("content").Count 就會有兩個,我們服務(wù)器端取值就稍稍有點不方便,得用 Request.Form("content")(0)。如果我們將 id 設(shè)為 fckcontent,那么 FCKeditor 文本區(qū)的 name 就是 fckcontent,與 textarea 不同名。
設(shè)置編輯器寬高
var oFCKeditor = new FCKeditor("fckcontent", 500, 300);
或
復(fù)制代碼 代碼如下:
var oFCKeditor = new FCKeditor("fckcontent");
oFCKeditor.Width = 500;
oFCKeditor.Height = 300;
設(shè)置工具條
var oFCKeditor = new FCKeditor("fckcontent", 500, 300, "Basic");
注意第四個參數(shù),其可選值有 Basic、Default,注意大小寫不可搞錯,分別表示基本工具條、默認(rèn)工具條(全部按鈕)。
設(shè)置初始值、設(shè)置值、取值
設(shè)置初始值
實際上設(shè)置初始值很少用,因為一般都是與 textarea 關(guān)聯(lián)的,故只是簡單列出來一下,不深究。說明一下,如果關(guān)聯(lián)的 textarea 存在,則賦初始值是沒有用的。
var oFCKeditor = new FCKeditor("fckcontent2", 500, 300, "Default", "腳本之家");
或
復(fù)制代碼 代碼如下:
var oFCKeditor = new FCKeditor("fckcontent2", 500, 300, "Default");
oFCKeditor.BasePath = "fckeditor/";
oFCKeditor.Value = "cftea"; // 必須在 Create 之前
oFCKeditor.Create();
設(shè)置值
若要演示此示例,最好是放在按鈕的事件處理程序中,目的是有些延遲,否則會說 FCKeditorAPI 未定義。
復(fù)制代碼 代碼如下:
var oEditor = FCKeditorAPI.GetInstance("fckcontent");
oEditor.SetHTML("腳本之家");
取值
若要演示此示例,最好是放在按鈕的事件處理程序中,目的是有些延遲,否則會說 FCKeditorAPI 未定義。
復(fù)制代碼 代碼如下:
var oEditor = FCKeditorAPI.GetInstance("fckcontent");
alert(oEditor.GetXHTML()); // 還有個類似方法是 GetHTML,但不推薦用 GetHTML。
您這樣做很危險:
復(fù)制代碼 代碼如下:
var oEditor = FCKeditorAPI.GetInstance("fckcontent");
oEditor.SetHTML("腳本之家");
alert(oEditor.GetXHTML()); // 這里的值并不一定是上一句賦的值。因為他們太近了,值還沒來得及賦,就已經(jīng) alert 了。
插入圖片
若要演示此示例,最好是放在按鈕的事件處理程序中,目的是有些延遲,否則會說 FCKeditorAPI 未定義。
FCKeditorAPI.GetInstance("fckcontent").InsertHtml("<img src...>");
相關(guān)文章
php下FCKeditor2.6.5網(wǎng)頁編輯器的使用方法
php下FCKeditor2.6.5網(wǎng)頁編輯器的使用方法,需要的朋友可以參考下。2009-12-12
FCKeditor smarty 編輯器的應(yīng)用PHP
自己仔細(xì)研究一下很容易解決你這個問題的。這并不是一個很困難的任務(wù)。其實這里很多都是菜鳥級別的2012-07-07
FCK編輯器(FCKEditor)添加新按鈕和功能的修改方法
最近項目需要對已有的FCKeditor添加新的功能,以前的做法只是在外殼處再次封裝,這次無法滿足需求只能進(jìn)行內(nèi)部修改了。2010-11-11
關(guān)于jsp版ueditor1.2.5的部分問題解決(上傳圖片失敗)
這篇文章主要介紹大家在使用jsp版ueditor1.2.5的碰到的一些問題解決方法,需要的朋友可以參考下2013-06-06
FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合
FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合方法,里面有下載,可以根據(jù)需要結(jié)合自己的fckeditor版本。2010-04-04
百度UEditor修改右下角統(tǒng)計字?jǐn)?shù)包含html樣式
百度UEditor修改右下角統(tǒng)計字?jǐn)?shù)默認(rèn)只統(tǒng)計前臺所見的文字個數(shù),如何讓右下角統(tǒng)計字?jǐn)?shù)包含html樣式,需要的朋友可以參考下2014-07-07

