fckeditor常用Js,获取fckeditor内容,统计fckeditor字数,向fckeditor写入指定代码
程序员文章站
2022-03-20 15:06:29
content相当于你例子中的fckeditor1。 复制代码 代码如下: //获取格式化的编辑器内容 function geteditorcontents(){ var...
content相当于你例子中的fckeditor1。
//获取格式化的编辑器内容
function geteditorcontents(){
var oeditor = fckeditorapi.getinstance(“content”);
alert(oeditor.getxhtml(true));
}
//向编辑器插入指定代码
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() ;
}
//设置编辑器中内容
function setcontents(codestr){
var oeditor = fckeditorapi.getinstance(“content”) ;
oeditor.sethtml(codestr) ;
}
复制代码 代码如下:
//获取格式化的编辑器内容
function geteditorcontents(){
var oeditor = fckeditorapi.getinstance(“content”);
alert(oeditor.getxhtml(true));
}
//向编辑器插入指定代码
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() ;
}
//设置编辑器中内容
function setcontents(codestr){
var oeditor = fckeditorapi.getinstance(“content”) ;
oeditor.sethtml(codestr) ;
}