国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 軟件應用 > 正文

使用Js獲取、插入和更改FCKeditor編輯器里的內容

2024-09-06 19:17:04
字體:
來源:轉載
供稿:網友

之前在一個系統里使用了FCKeditor編輯器,由于項目需求需要在FCKeditor里添加一個自定義的按鈕用于實現自己的需求

主要是在點擊該按鈕時刪除或添加FCKeditor編輯器里的內容

其實是一個很簡單的需求,本來以為在FCKeditor可以很容易的實現
在Google上搜索自定義按鈕,插件開發,經過近二個小時的摸索最終還是沒有實現不知是我太笨還是自定義插件太難啦

通過JS方式來處理

1.在頁面中添加checkbox元素并綁定事件,選中該元素時將在FCKeditor內容里添加"{#book#}"字符串(該字符串會在適當的時候被替換成其他內容),取消選中時則刪除

<label><input type="checkbox" id="lineBook" onclick="chk_but();"/>添加/刪除復選框</label>

2.添加Js處理FCKeditor內容(添加或刪除"{#book#}"字符串),'txtContent'為FCKeditor的ID控控件ID

<script type = "text/javascript" >//"添加/刪除復選框"點擊時如果按鈕選中則添加"{#book#}"字符串到FCK內容里,反之刪除字符串//lineBook為FCK的ID號function chk_but() {  if (window.FCKeditorAPI !== undefined && FCKeditorAPI.GetInstance('txtContent') !== undefined) {    if (document.getElementById('lineBook').checked) {      FCKeditorAPI.GetInstance('txtContent').EditorDocument.body.innerHTML += "{#book#}";    } else {      FCKeditorAPI.GetInstance('txtContent').EditorDocument.body.innerHTML = FCKeditorAPI.GetInstance('txtContent').EditorDocument.body.innerHTML.replace("{#book#}", "");    }  }} //end function chk_lineBook()//內容里如果有{#book#}則選中"添加/刪除復選框"if (document.getElementById('txtContent').value.indexOf('{#book#}') >= 0   && window.FCKeditorAPI !== undefined   && FCKeditorAPI.GetInstance('txtContent') !== undefined) {  document.getElementById('lineBook').checked = true;} </script>

參考:

官網:http://ckeditor.com/

獲取或更改內容值:http://bbs.csdn.net/topics/360086762

創建插件:http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/Customization/Plug-ins

接著給大家分享一下JS操作Fckeditor的一些常用方法

//向編輯器插入指定代碼 function insertHTMLToEditor(codeStr){  var oEditor = FCKeditorAPI.GetInstance("content"); oEditor.InsertHtml(codeStr); // "html"為HTML文本}//獲取編輯器中HTML內容function getEditorHTMLContents() { var oEditor = FCKeditorAPI.GetInstance("content"); return(oEditor.GetXHTML(false));}// 獲取編輯器中文字內容function getEditorTextContents() { var oEditor = FCKeditorAPI.GetInstance("content"); return(oEditor.EditorDocument.body.innerText);}// 設置編輯器中內容function SetEditorContents(ContentStr) { var oEditor = FCKeditorAPI.GetInstance("content") ; oEditor.SetHTML(ContentStr) ;}//向編輯器插入指定代碼 function insertHTMLToEditor(codeStr){   var oEditor = FCKeditorAPI.GetInstance( "content ");   if (oEditor.EditMode==FCK_EDITMODE_WYSIWYG){     oEditor.InsertHtml(codeStr);   }else{     return false;   } } //統計編輯器中內容的字數 function getLength(){   var oEditor = FCKeditorAPI.GetInstance( "content ");   var oDOM = oEditor.EditorDocument;   var iLength ;   if(document.all){     iLength = oDOM.body.innerText.length;   }else{     var r = oDOM.createRange();     r.selectNodeContents(oDOM.body);     iLength = r.toString().length;   }   alert(iLength); } //執行指定動作 function ExecuteCommand(commandName){   var oEditor = FCKeditorAPI.GetInstance( "content ") ;   oEditor.Commands.GetCommand(commandName).Execute() ; }

到此這篇關于使用Js獲取、插入和更改FCKeditor編輯器里的內容的文章就介紹到這了,更多相關Js操作FCKeditor編輯器內容請搜素武林網以前的文章或下面相關文章,希望大家以后多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无极县| 新化县| 台中市| 石泉县| 潢川县| 汤阴县| 巴青县| 南郑县| 霍邱县| 吉隆县| 周口市| 安康市| 沁源县| 舒兰市| 兴宁市| 揭西县| 云南省| 方山县| 上虞市| 泗洪县| 凌海市| 新巴尔虎右旗| 景洪市| 平顶山市| 基隆市| 茂名市| 安泽县| 永登县| 拜泉县| 内江市| 霍城县| 安化县| 镇雄县| 宣汉县| 新丰县| 新民市| 全椒县| 泌阳县| 定南县| 普安县| 勐海县|