Fckeditor编辑器内容长度限制统计实现方法
更新时间:2012年03月03日 00:15:12 作者:
Fckeditor是一种大家常用的编辑器,但是他不能像网页表单那样利用document.getelementbyid能获取得到值了,它必须通过 FCKeditorAPI来操作,下面看看Fckeditor内容长度测试
先我们看最简单的就是编辑器的代码了,简单得很同时大家也经常看过。
<script type="text/javascript" src="/editor/fckeditor.js"></script>
<script type="text/javascript">
<!--
var oFCKeditor = new FCKeditor( 'Content' ) ;
oFCKeditor.BasePath = "/editor/" ;
oFCKeditor.ToolbarSet = "User" ;
oFCKeditor.Value = '没有最好,只有更好,大家努力' ;
oFCKeditor.Height = 450 ;
oFCKeditor.Width = 660 ;
oFCKeditor.Create() ;
//-->
</script>
<input type="button" value="检测字数(包括HTML代码)" style="width:165px;" class="inputc" onClick="checklength()">
<script>
//检测在线编器字符数 ,他必须通过创建FCKeditorAPI来实现,代码如下。
function checklength()
{
var Content;
var oEditor = FCKeditorAPI.GetInstance('Content') ;
Content=oEditor.GetXHTML(true)
alert("n当前: "+Content.length+" 个字符");
return false;
}
</script>
再看实例,这里限制了fckeditor编辑器内容的长度哦,
window.onload=function(){
function FCKeditor_OnComplete()
{
var editor = FCKeditorAPI.GetInstance('info') ;
editor.Events.AttachEvent('OnSelectionChange', editor_keydown);
}
function editor_keydown(editor)
{
var maxLength=3; //最大输入字数
content= $(editor.EditorDocument.body).text();
var len= content.length;
var $info =$('#info');//存放提示信息
if(len < maxLength){
.text("还可以输入 "+(maxLength-len)+"字");
}
if(len == maxLength){
$info.text("字数达到上限");
}
if(len > maxLength){
$info.text(" 输入字符超过"+maxLength+"个,请更改!");
}
}
FCKeditor_OnComplete()
}
复制代码 代码如下:
<script type="text/javascript" src="/editor/fckeditor.js"></script>
<script type="text/javascript">
<!--
var oFCKeditor = new FCKeditor( 'Content' ) ;
oFCKeditor.BasePath = "/editor/" ;
oFCKeditor.ToolbarSet = "User" ;
oFCKeditor.Value = '没有最好,只有更好,大家努力' ;
oFCKeditor.Height = 450 ;
oFCKeditor.Width = 660 ;
oFCKeditor.Create() ;
//-->
</script>
<input type="button" value="检测字数(包括HTML代码)" style="width:165px;" class="inputc" onClick="checklength()">
<script>
//检测在线编器字符数 ,他必须通过创建FCKeditorAPI来实现,代码如下。
复制代码 代码如下:
function checklength()
{
var Content;
var oEditor = FCKeditorAPI.GetInstance('Content') ;
Content=oEditor.GetXHTML(true)
alert("n当前: "+Content.length+" 个字符");
return false;
}
</script>
再看实例,这里限制了fckeditor编辑器内容的长度哦,
复制代码 代码如下:
window.onload=function(){
function FCKeditor_OnComplete()
{
var editor = FCKeditorAPI.GetInstance('info') ;
editor.Events.AttachEvent('OnSelectionChange', editor_keydown);
}
function editor_keydown(editor)
{
var maxLength=3; //最大输入字数
content= $(editor.EditorDocument.body).text();
var len= content.length;
var $info =$('#info');//存放提示信息
if(len < maxLength){
.text("还可以输入 "+(maxLength-len)+"字");
}
if(len == maxLength){
$info.text("字数达到上限");
}
if(len > maxLength){
$info.text(" 输入字符超过"+maxLength+"个,请更改!");
}
}
FCKeditor_OnComplete()
}
您可能感兴趣的文章:
相关文章
fckeditor在ie9中无法弹出对话框的解决方法(弹出层兼容问题)
升级到 IE 9后,fckeditor在IE 9里的弹出浮动层会出现bug,里面的内容不会出现2012-04-04
编辑器中designMode和contentEditable的属性的介绍
先解释一下在线编辑器的原理:首先需要IE5.0以上版本的支持.因为IE5.0以上版本有一个编辑状态,designMode是document的属性,意思是设置或获取表明文档是否可被编辑的值,默认值为off或Inherit2008-11-11
FCKeditor提供了一个完整的JavaScript API
FCKeditor提供了一个完整的JavaScript API(Application Public Interface),你可以利用这些API来处理FCK编辑器,只要它被加载完成或在正在运行中.2009-12-12
百度编辑器 ueditor 内容编辑自动套P标签,及p标签 替换
这篇文章主要介绍了百度编辑器 ueditor 内容编辑自动套P标签,及p标签 替换,需要的朋友可以参考下2017-03-03


最新评论