一、FCKeditor的配置使用
拷貝fckeditor文件到webroot目錄下,右擊文件根目錄--MyEclipse--Exculde From Validation--不進行有效性驗證
1._samples文件夾爲例子
2.頁面添加如下代碼
<script src="/guestbook/fckeditor/fckeditor.js"></script> //設置js文件路徑
<script>
var editor=new FCKeditor('name'); //實例化--設置文本域名字
editor.BasePath='/guestbook/fckeditor/'; //fck根目錄
editor.Height=200; //設置編輯器高度
editor.ToolbarSet='Default'; Basic:精簡版 / Default:完整版 //工具欄設置
editor.Create(); //創建
</script>
自定樣式:fckconfig.js
['Bold','Italic','Underline','-','JustifyLeft','JustifyCenter','JustifyRight','OrderedList','UnorderedList','-','Undo','Redo','-','Link','Unlink','-','Smiley','TextColor','BGColor','Rule'],
['Style','FontFormat','FontName','FontSize']
3.接受值:request.getParameter("name"))
4.瘦身:
一級目錄: 保留文件--fckconfig.js,fckeditor.js,fckstyles.xml
二級目錄editor: 刪_source plugins
三級editor.lang目錄: 保留zh.js zh-cn.js en.js
editor.skins目錄: 刪office2003,silver文件
二、更換皮膚
如果想更換皮膚:
將皮膚文件夾中的文件考入skins包:
並更改配置:
找到此行:FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ;
用office2003:就將default改成office2003
還有silver等皮膚
三、圖片上傳路徑:
PHP:
1.打開 \Public\Js\FCKeditor\editor\filemanager\connectors\語言種類\config.php文件,修改
$Config['UserFilesPath'] = '/你的項目名稱/存放圖片的文件夾' ;
// 如 $Config['UserFilesPath'] = '/xlmxbgCMS2TP2.0/Public/userFiles/' ;
2.在 \xlmxbgCMS2TP2.0\Public\ 目錄下新建文件夾 userFiles (對應上面的例子,最好手動創建一下文件夾)
其他語言的圖片、flash登上傳功能暫不介紹。
四、JS獲取fckeditor中內容:
// 獲取編輯器中HTML內容
function getEditorHTMLContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.GetXHTML(true));
}
// 獲取編輯器中文字內容
function getEditorTextContents(EditorName) {
var oEditor = FCKeditorAPI.GetInstance(EditorName);
return(oEditor.EditorDocument.body.innerText);
}
// 配置編輯器中內容
function SetEditorContents(EditorName, ContentStr) {
var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
oEditor.SetHTML(ContentStr) ;
}
五、顯示數據問題:
1.存儲數據時會自動在數據後添加“,”號。
原因:在頁面中有相同名的表單元素。
2.用編輯器存儲的數據的特殊字符都轉換爲html代碼,
解決:所以顯示用編輯器存儲的數據時:先添加一個隱藏的層,
<span id="contents" style="display:none"><p>This is right content!!!</p></span>
然後在fckeditor的配置中添加:editor.Value=contents.innerText;
這樣,以上問題都解決了。