javascript獲取和設置FCKeditor內容
利用Javascript取和設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) ; }FCKeditorAPI是FCKeditor加載后注冊的一個全局對象,利用它我們就可以完成對編輯器的各種操作。
在當前頁獲得 FCK 編輯器實例:
var Editor = FCKeditorAPI.GetInstance('InstanceName');
從 FCK 編輯器的彈出窗口中獲得 FCK 編輯器實例:
var Editor = window.parent.InnerDialogLoaded().FCK;
從框架頁面的子框架中獲得其它子框架的 FCK 編輯器實例:
var Editor = window.FrameName.FCKeditorAPI.GetInstance('InstanceName');
從頁面彈出窗口中獲得父窗口的 FCK 編輯器實例:
var Editor = opener.FCKeditorAPI.GetInstance('InstanceName');
獲得 FCK 編輯器的內容:
oEditor.GetXHTML(formatted); // formatted 為:true|false,表示是否按HTML格式取出
也可用:
oEditor.GetXHTML();
設置 FCK 編輯器的內容:
oEditor.SetHTML("content", false); // 第二個參數(shù)為:true|false,是否以所見即所得方式設置其內容。此方法常用于"設置初始值"或"表單重置"哦作。
插入內容到 FCK 編輯器:
oEditor.InsertHtml("html"); // "html"為HTML文本
檢查 FCK 編輯器內容是否發(fā)生變化:
oEditor.IsDirty();
在 FCK 編輯器之外調用 FCK 編輯器工具條命令:
命令列表如下:
DocProps, Templates, Link, Unlink, Anchor, BulletedList, NumberedList, About, Find, Replace, Image, Flash, SpecialChar, Smiley, Table, TableProp, TableCellProp, UniversalKey, Style, FontName, FontSize, FontFormat, Source, Preview, Save, NewPage, PageBreak, TextColor, BGColor, PasteText, PasteWord, TableInsertRow, TableDeleteRows, TableInsertColumn, TableDeleteColumns, TableInsertCell, TableDeleteCells, TableMergeCells, TableSplitCell, TableDelete, Form, Checkbox, Radio, TextField, Textarea, HiddenField, Button, Select, ImageButton, SpellCheck, FitWindow, Undo, Redo
使用方法如下:
oEditor.Commands.GetCommand('FitWindow').Execute();
= FCKConfig.BasePath + 'plugins/'
// FCKConfig.Plugins.Add( 'placeholder', 'en,it' ) ;
去掉//后,就相當于把placeholder這個插件功能加上了,fckeditor的插件文件都在/editor/plugins/文件夾下分類按文件夾放置的,對于fckeditor2.0來說,里面有兩個文件夾,也就是有兩個官方插件,placeholder這個文件夾就是我們剛才加上去的,主要用于多參數(shù)或單參數(shù)自定義標簽的匹配,這個在制作編輯模板時非常管用,要想看具體實例的話,大家可以去下載acms 這個系統(tǒng)查看學習,另一個文件夾tablecommands就是編輯器里的表格編輯用到的了。當然,如果你想制作自己其它用途的插件,那就只要按照 fckeidtor插件的制作規(guī)則制作完放置在/editor/plugins/下就行,然后再在fckeidtor.js里再添加 FCKConfig.Plugins.Add('Plugin Name',',lang,lang');就可以了。
新聞熱點
疑難解答
圖片精選