黑松山资源网 Design By www.paidiu.com
之前在一个系统里使用了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() ; }
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年05月20日
2024年05月20日
- 崩坏星穹铁道梦中之梦12平民满星攻略 梦中之梦12阵容搭配分享
- 钟志刚《淡淡君情》24K金限量头版[低速原抓WAV+CUE]
- 金山游戏封神再临视频首曝 预计年内上线
- IGN分享PC《对马岛之魂》28分钟实机:极致的画面表现
- 崩坏星穹铁道平民神主日怎么打 神主日萌新通关攻略
- 蜀门手游五月大服龙城飞将开启 全新大逃杀玩法上线
- 钟明秋《是时候HQ》头版限量编号[低速原抓WAV分轨]
- 赵传《我是一只小小鸟》日本东芝1A1版 [WAV+CUE][435M]
- 庄达菲《东张西望》[320K/MP3][40.28MB]
- 庄达菲《东张西望》[24bit 48kHz][FLAC/分轨][288.46MB]
- 金海心.-.[心感觉].专辑[原抓WAV+CUE]
- KOKIA心は?かり(2012K2HD2016Mora)[24bit96kHzFLAC]
- 林一峰2017-绝对清白2CD[香港首版][WAV+CUE
- 石凯《数星一整夜》[320K/MP3][44.18MB]
- 石凯《数星一整夜》[24bit 48kHz][FLAC/分轨][395.49MB]