您现在的位置是:网站首页> 编程资料编程资料
使用Js获取、插入和更改FCKeditor编辑器里的内容_网页编辑器_
2023-05-25
419人已围观
简介 使用Js获取、插入和更改FCKeditor编辑器里的内容_网页编辑器_
之前在一个系统里使用了FCKeditor编辑器,由于项目需求需要在FCKeditor里添加一个自定义的按钮用于实现自己的需求
主要是在点击该按钮时删除或添加FCKeditor编辑器里的内容
其实是一个很简单的需求,本来以为在FCKeditor可以很容易的实现
在Google上搜索自定义按钮,插件开发,经过近二个小时的摸索最终还是没有实现不知是我太笨还是自定义插件太难啦
通过JS方式来处理
1.在页面中添加checkbox元素并绑定事件,选中该元素时将在FCKeditor内容里添加"{#book#}"字符串(该字符串会在适当的时候被替换成其他内容),取消选中时则删除
2.添加Js处理FCKeditor内容(添加或删除"{#book#}"字符串),'txtContent'为FCKeditor的ID控控件ID
参考:
官网: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编辑器内容请搜素以前的文章或下面相关文章,希望大家以后多多支持!
相关内容
- 自动刷新从BrowserSync开始_网页编辑器_
- 使用 CodeMirror 打造属于自己的带高亮显示的在线代码编辑器_网页编辑器_
- 基于开发中使用UEditor编辑器的注意事项详解_网页编辑器_
- 快速解决百度编译器json报错的问题_网页编辑器_
- php UEditor百度编辑器安装与使用方法分享_网页编辑器_
- Ueditor百度编辑器的Html模式自动替换样式的解决方法_网页编辑器_
- 百度编辑器 ueditor 内容编辑自动套P标签,及p标签 替换_网页编辑器_
- 百度编辑器Ueditor增加字体的修改方法_网页编辑器_
- Prism 代码高亮修改不包含 Code 标签的支持_网页编辑器_
- UEditor 默认字体和字号的修改方法_网页编辑器_
