亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费

使用Js獲取、插入和更改FCKeditor編輯器里的內容
發(fā)布時(shí)間:2026-05-04 18:25:21

這篇文章主要介紹了使用(yong)Js獲取、使??用插(′;д;`)入和更改FCKeditor(′?_?`)編輯器里的獲取和更內容,包括JS操作Fckeditor的插入一些常用方法,需要的朋友可以參考下

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

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

其實(shí)是一個(gè)(′▽?zhuān)?很簡(jiǎn)單的需求,本來(lái)以為在FCKeditor可以很容易的器里實(shí)現

在Google上搜索自定義按鈕,插件開(kāi)發(fā),經(jīng)過(guò)近二個(gè)小時(shí)的使用┐(′?`)┌摸索最終還是沒(méi)有實(shí)現不知是我太笨還是自定(′?_?`)義插件太難啦

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

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

添加/刪除復選框

2.添加Js(′▽?zhuān)?處理FCKeditor內容(添加或刪除"{ #book#}"字符串),( ?ω?)'txtContent'為FCK??editor的ID控控件ID

<script typヽ(′ー`)ノe = "text/javascript" >
//"添加/刪除復選框"點(diǎn)擊??時(shí)如果按鈕選中則添加"{ #book#}"字符串到FCK內容里,反之刪除字符串
//lineBook為FCK的獲取和更ID號
fu??n(′?`)ctio???n chk_but() {
if (window.FCKeditorAPI !== undef??ined && FCKeditorAPI.GetInstance('txtContent') !== undefined) {
if (document.getElementById('lineBook').checked='checked') {
FCKeditorAPI.GetInstanc??e('txtCon??tent').EditorDocument.body.innerHTML += "{ #book#}";
} else {
FCKeditorAPI.GetInstance('txtContent').EditorDocument.body.innerHTMLヾ(′▽?zhuān)?? = FCKeditorAPI.G(′Д` )etInstance??('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.getElementBy(╬?益?)Id('lineBook').checked = true;
}
<??;/script>

參考:

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

獲取或更改內容值:httpヾ(′ω`)?://bbs.csdn.net/topics/360086762

創(chuàng )建插件(′_`):http://(′▽?zhuān)?)docs.cksource.com/FCKeditor_2.x/Developers_Guide/Customization/Plug-ins

//向編輯器(qi)插入指定代碼
function insertHTMLToEditヽ(′▽?zhuān)?ノor(codeStr){
var oEditor = FCKeditorAPI.GetInstance("content");
oEditor.InsertHtml(codeStr); // "html"為HTML文本
}
//??獲取編輯器中HTML內容
function getEditorHTMLContents() {
var oEditor = FCKeditorAPI.Get(′?ω?`)Instヾ(′?`)?ance("content");
return(oEditor.GetXHTML(fals??e));
}
// 獲取編輯器中文字內容
fu??nction getEditorTextContents() {
var oEditor = FCKeditorAPI.GetInstance("content");
return(oEditor.EditorDocument.body.innerTeヽ(′ー`)ノxt);
}
// 設置編輯器中內( ???)容
function(′?`*) SetEditorContents(ContentStr) {
var oEditor = FC??KeditorAPI.GetInstance("content") ;
oEditor.SetHTML(ContentStr) ;
}
//向編輯器插入指定代碼
function?? insertHTMLToEditor(codeStr){
var oEdi(′ω`)tor = 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.Ed??itorDocument;
var iLength ;
if(document.all){
iLength = oDOM(′ω`).body.innerText.length;
}else{
var r = oDOM.createRange();
r.selectNodeContent??s(oDOM.body);
iLeng??th = r.toString(??).length;
}
alert(iLength);
}
//執行指定動(dòng)作
function ExecuteCommand(commandName){
var oEditor = FCKeditorAPI.GetInstance( "content ") ;
oEditor(??-)?.Commands.GetCommanヽ(′ー`)ノd(commandNa??me).Execute() ;
}

本文來(lái)自腳本之家,原文鏈接:https://www.jb51.net/article/180847.htm

插入
亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费 孟津县| 吉木萨尔县| 沽源县| 屯门区| 呈贡县| 乡城县| 文登市| 大港区| 镇雄县| 安阳市| 玉门市| 平度市| 通道| 五大连池市| 砚山县| 临江市| 松潘县| 涿州市| 苍南县| 聂拉木县| 清流县| 汉源县| 平遥县| 金华市| 即墨市| 义马市| 宁乡县| 清远市| 正阳县| 惠州市| 广东省| 尉氏县| 宝清县| 青冈县| 赤峰市| 班玛县| 柳江县| 泗水县| 呼伦贝尔市| 财经| 青岛市| http://444 http://444 http://444 http://444 http://444 http://444