js提取指定网站内容( 2020年02月19日16:50:52作者huangtailangJS操作Fckeditor)
优采云 发布时间: 2022-01-03 04:02js提取指定网站内容(
2020年02月19日16:50:52作者huangtailangJS操作Fckeditor)
在 FCKeditor 编辑器中使用 Js 获取、插入和更改内容
更新时间:2020-02-19 16:50:52 作者:huangtailang
这个文章主要介绍了在FCKeditor编辑器中使用js获取、插入和更改内容,包括一些js操作Fckeditor的常用方法,有需要的朋友可以参考
FCKeditor 编辑器之前在一个系统中使用过。由于项目需要,需要在FCKeditor中添加一个自定义按钮来实现自己的需求。
主要是在FCKeditor编辑器中点击按钮时删除或添加内容
其实就是一个很简单的需求。我认为它可以在 FCKeditor 中轻松实现。
在 Google 上搜索自定义按钮和插件开发。经过近两个小时的探索,我还是没有意识到。不知道是我太笨还是自定义插件太难了。
通过JS方法处理
1.页面添加checkbox元素并绑定事件。当这个元素被选中时,“{#book#}”字符串会被添加到FCKeditor内容中(该字符串会在合适的时候被替换为其他内容),不选中时删除
2.添加Js处理FCKeditor内容(添加或删除“{#book#}”字符串),'txtContent'为FCKeditor的ID控件ID
//"添加/删除复选框"点击时如果按钮选中则添加"{#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;
}
参考:
官网:
获取或更改内容值:
创建插件:
接下来给大家分享一些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() ;
}
这是文章关于在FCKeditor编辑器中使用Js获取、插入和更改内容的介绍。更多相关Js操作FCKeditor编辑器内容,请搜索之前的脚本首页文章或下方相关文章,希望大家以后多多支持Scripthome!