麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 網(wǎng)站 > 軟件應(yīng)用 > 正文

使用Js獲取、插入和更改FCKeditor編輯器里的內(nèi)容

2024-09-06 19:17:04
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

之前在一個(gè)系統(tǒng)里使用了FCKeditor編輯器,由于項(xiàng)目需求需要在FCKeditor里添加一個(gè)自定義的按鈕用于實(shí)現(xiàn)自己的需求

主要是在點(diǎn)擊該按鈕時(shí)刪除或添加FCKeditor編輯器里的內(nèi)容

其實(shí)是一個(gè)很簡(jiǎn)單的需求,本來(lái)以為在FCKeditor可以很容易的實(shí)現(xiàn)
在Google上搜索自定義按鈕,插件開(kāi)發(fā),經(jīng)過(guò)近二個(gè)小時(shí)的摸索最終還是沒(méi)有實(shí)現(xiàn)不知是我太笨還是自定義插件太難啦

通過(guò)JS方式來(lái)處理

1.在頁(yè)面中添加checkbox元素并綁定事件,選中該元素時(shí)將在FCKeditor內(nèi)容里添加"{#book#}"字符串(該字符串會(huì)在適當(dāng)?shù)臅r(shí)候被替換成其他內(nèi)容),取消選中時(shí)則刪除

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

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

<script type = "text/javascript" >//"添加/刪除復(fù)選框"點(diǎn)擊時(shí)如果按鈕選中則添加"{#book#}"字符串到FCK內(nèi)容里,反之刪除字符串//lineBook為FCK的ID號(hào)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()//內(nèi)容里如果有{#book#}則選中"添加/刪除復(fù)選框"if (document.getElementById('txtContent').value.indexOf('{#book#}') >= 0   && window.FCKeditorAPI !== undefined   && FCKeditorAPI.GetInstance('txtContent') !== undefined) {  document.getElementById('lineBook').checked = true;} </script>

參考:

官網(wǎng):http://ckeditor.com/

獲取或更改內(nèi)容值:http://bbs.csdn.net/topics/360086762

創(chuàng)建插件: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內(nèi)容function getEditorHTMLContents() { var oEditor = FCKeditorAPI.GetInstance("content"); return(oEditor.GetXHTML(false));}// 獲取編輯器中文字內(nèi)容function getEditorTextContents() { var oEditor = FCKeditorAPI.GetInstance("content"); return(oEditor.EditorDocument.body.innerText);}// 設(shè)置編輯器中內(nèi)容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;   } } //統(tǒng)計(jì)編輯器中內(nèi)容的字?jǐn)?shù) 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); } //執(zhí)行指定動(dòng)作 function ExecuteCommand(commandName){   var oEditor = FCKeditorAPI.GetInstance( "content ") ;   oEditor.Commands.GetCommand(commandName).Execute() ; }

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

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 在线成人免费av | 欧美在线一级 | 国产一级在线观看视频 | 亚洲免费视频大全 | 国产精品白嫩白嫩大学美女 | 国产黄色毛片 | 欧美日韩亚洲另类 | 成人性爱视频在线观看 | 久久2019中文字幕 | 免费视频www在线观看 | 国产成人羞羞视频在线 | 精品中文一区 | 懂色av懂色aⅴ精彩av | 黄色免费不卡视频 | 久久影院一区二区三区 | 日本a级免费 | 国产日韩a | 欧美日韩一 | 免费观看视频91 | 羞羞的视频 | 国产瑟瑟视频 | 亚洲综合色视频在线观看 | av电影免费播放 | 一区播放 | 国产午夜精品理论片a级探花 | 国产精品久久久久久婷婷天堂 | 999久久国产 | 热99精品视频| 亚久久| 成人情欲视频在线看免费 | 精品在线观看一区二区三区 | 宅男噜噜噜66一区二区 | 国产一区二区三区四区五区在线 | 久久久三区 | 国产乱淫a∨片免费视频 | 视频一区二区精品 | 成人免费观看49www在线观看 | 369看片你懂的小视频在线观看 | 欧美韩国日本在线 | 欧美精品一级片 | 精品一区二区三区免费毛片爱 |