FCK 相關函數

文本框改變事件.開始 <textarea cols="1" rows="1" id="txt2" name="txt2" style="width: 400px; height: 60px;"  ></textarea>                 <script type="text/javascript" language="javascript">             var scpMgr = new CaptureManager();             //http://www.ncmem.com/products/screencapture/demo/upload.aspx,若是不是這個域名。可能出現域名未受權現象             //scpMgr.Config["PostUrl"] = "http://192.168.0.100/market/asp.net/upload.aspx";             scpMgr.Config["PostUrl"] = "http://www.ncmem.com/products/screencapture/demo/upload.aspx";             var oFCKeditor = new FCKeditor('txt2');             oFCKeditor.BasePath = "fckeditor/";             oFCKeditor.ToolbarSet = 'Basic';             oFCKeditor.Width = "400";             oFCKeditor.Height = "200";             oFCKeditor.ReplaceTextarea();                         function FCKeditor_OnComplete(editorInstance) {                 scpMgr.Init(editorInstance); //初始化                 editorInstance.EditorDocument.attachEvent("onkeydown", editor_keydown);             }             function editor_keydown() {                 var oEditor = FCKeditorAPI.GetInstance("txt2");                 var str1 = oEditor.GetXHTML(true);                 alert(str1); //                if (str1.indexof('src="/upload') > 0) { //                    str1 = str1.replace('src="/upload', "http://www.ncmem.com/upload"); //                } //                oEditor.SetHTML(str1, false);             }     </script> 文本框改變事件.結束 獲取FCK的實例 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獲取焦點 獲 取焦點是否在FCK中: oEditor.HasFocus FCK獲取焦點: oEditor.Focus();// 獲取焦點 獲取和設置FCK的內容 得到 FCK 編輯器的內容: oEditor.GetXHTML(formatted); // formatted 爲:true|false,表示是否按HTML格式取出。 設置 FCK 編輯器的內容: oEditor.SetHTML("content", false); // 第二個參數爲:true|false,是否以所見即所得方式設置其內容。 插入內容到 FCK 編輯器: oEditor.InsertHtml("html"); // "html"爲HTML文本 檢查 FCK 編輯器內容是否發生變化: oEditor.IsDirty(); 1 // 獲取編輯器中HTML內容 2 function getEditorHTMLContents(EditorName) { 3 var oEditor = FCKeditorAPI.GetInstance(EditorName); 4 return(oEditor.GetXHTML(true)); 5 } 6 7 // 獲取編輯器中文字內容 8 function getEditorTextContents(EditorName) { 9 var oEditor = FCKeditorAPI.GetInstance(EditorName); 10 return(oEditor.EditorDocument.body.innerText); 11 } 12 13 // 設置編輯器中內容 14 function SetEditorContents(EditorName, ContentStr) { 15 var oEditor = FCKeditorAPI.GetInstance(EditorName) ; 16 oEditor.SetHTML(ContentStr) ; 17 } 18 FCK的事件處理 FCK 定義有OnComplete,OnBlur和OnFocus等事件,這樣就能夠使用事件的處理函數完成相應的處理。 FCK添加事件處理 函數的方法是:fckInstance.Events.AttachEvent( EventName, function) 代碼 //FCKeditor 加載完成後作處理的方法 function FCKeditor_OnComplete( editorInstance ) { editorInstance.Events.AttachEvent( 'OnBlur' , FCKeditor_OnBlur ) ; editorInstance.Events.AttachEvent( 'OnFocus', FCKeditor_OnFocus ) ; } function FCKeditor_OnBlur( editorInstance ) { //失去焦點收起工具欄 editorInstance.ToolbarSet.Collapse() ; } function FCKeditor_OnFocus( editorInstance ) { editorInstance.ToolbarSet.Expand() ; }
相關文章
相關標籤/搜索