Fckeditor編輯器內(nèi)容長度限制統(tǒng)計實現(xiàn)方法
更新時間:2012年03月03日 00:15:12 作者:
Fckeditor是一種大家常用的編輯器,但是他不能像網(wǎng)頁表單那樣利用document.getelementbyid能獲取得到值了,它必須通過 FCKeditorAPI來操作,下面看看Fckeditor內(nèi)容長度測試
先我們看最簡單的就是編輯器的代碼了,簡單得很同時大家也經(jīng)??催^。
<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="檢測字?jǐn)?shù)(包括HTML代碼)" style="width:165px;" class="inputc" onClick="checklength()">
<script>
//檢測在線編器字符數(shù) ,他必須通過創(chuàng)建FCKeditorAPI來實現(xiàn),代碼如下。
function checklength()
{
var Content;
var oEditor = FCKeditorAPI.GetInstance('Content') ;
Content=oEditor.GetXHTML(true)
alert("n當(dāng)前: "+Content.length+" 個字符");
return false;
}
</script>
再看實例,這里限制了fckeditor編輯器內(nèi)容的長度哦,
window.onload=function(){
function FCKeditor_OnComplete()
{
var editor = FCKeditorAPI.GetInstance('info') ;
editor.Events.AttachEvent('OnSelectionChange', editor_keydown);
}
function editor_keydown(editor)
{
var maxLength=3; //最大輸入字?jǐn)?shù)
content= $(editor.EditorDocument.body).text();
var len= content.length;
var $info =$('#info');//存放提示信息
if(len < maxLength){
.text("還可以輸入 "+(maxLength-len)+"字");
}
if(len == maxLength){
$info.text("字?jǐn)?shù)達到上限");
}
if(len > maxLength){
$info.text(" 輸入字符超過"+maxLength+"個,請更改!");
}
}
FCKeditor_OnComplete()
}
復(fù)制代碼 代碼如下:
<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="檢測字?jǐn)?shù)(包括HTML代碼)" style="width:165px;" class="inputc" onClick="checklength()">
<script>
//檢測在線編器字符數(shù) ,他必須通過創(chuàng)建FCKeditorAPI來實現(xiàn),代碼如下。
復(fù)制代碼 代碼如下:
function checklength()
{
var Content;
var oEditor = FCKeditorAPI.GetInstance('Content') ;
Content=oEditor.GetXHTML(true)
alert("n當(dāng)前: "+Content.length+" 個字符");
return false;
}
</script>
再看實例,這里限制了fckeditor編輯器內(nèi)容的長度哦,
復(fù)制代碼 代碼如下:
window.onload=function(){
function FCKeditor_OnComplete()
{
var editor = FCKeditorAPI.GetInstance('info') ;
editor.Events.AttachEvent('OnSelectionChange', editor_keydown);
}
function editor_keydown(editor)
{
var maxLength=3; //最大輸入字?jǐn)?shù)
content= $(editor.EditorDocument.body).text();
var len= content.length;
var $info =$('#info');//存放提示信息
if(len < maxLength){
.text("還可以輸入 "+(maxLength-len)+"字");
}
if(len == maxLength){
$info.text("字?jǐn)?shù)達到上限");
}
if(len > maxLength){
$info.text(" 輸入字符超過"+maxLength+"個,請更改!");
}
}
FCKeditor_OnComplete()
}
您可能感興趣的文章:
- FCKEditor超級鏈接默認(rèn)新窗口打開的修改方法
- Smarty中調(diào)用FCKeditor的方法
- fckeditor編輯器下的自定義分頁符實現(xiàn)方法
- FCKeditor編輯器添加圖片上傳功能及圖片路徑問題解決方法
- ThinkPHP中FCKeditor編輯器的使用方法
- fckeditor編輯器在php中的配置方法
- FCKeditor 圖片上傳進度條不動的解決方法
- php在頁面中調(diào)用fckeditor編輯器的方法
- 瀏覽器執(zhí)行history.go(-1) FCKeditor編輯框內(nèi)顯示html源代碼的解決方法
- FCK編輯器(FCKEditor)添加新按鈕和功能的修改方法
- fckeditor粘貼Word時彈出窗口取消的方法
相關(guān)文章
在kindEditor中獲取當(dāng)前光標(biāo)的位置索引的實現(xiàn)代碼
一直在用KindEditor,今天要用到光標(biāo)的位置,然后就gg一下辦法,后來發(fā)現(xiàn)這東西的編輯區(qū)域居然是iframe里面的一個body,不是textarea/input,后來就翻開了他的代碼看,發(fā)現(xiàn)有個insertHtml2011-11-11syntaxhighlighter 去掉右上角問號圖標(biāo)的三種方法
syntaxhighlighter可以高亮著色顯示幾乎所有語言形式的源代碼,還可以顯示行號,是一款深受網(wǎng)站建設(shè)人員喜愛的工具,并且它還是免費的2013-11-11CKeditor與syntaxhighlight打造joomla代碼高亮
最近在用csdn和cnblogs發(fā)帖子和寫隨筆的時候,發(fā)現(xiàn)了好多的IT的網(wǎng)站或者和代碼有關(guān)系的一些論壇,博客之類,他們都有一個非常好的語法高亮!很強大!2010-07-07在asp.net中KindEditor編輯器的使用方法小結(jié)
由于國外的服務(wù)器好象對一些要引用dll編輯器由于安全問題,鎖定了web.config中的一些權(quán)限,在先試了FreeTexbox不行,FCKEditor也不行,因為都是要引用dll文件,最后同事介紹一款 純js的kindeditor編輯器,2010-12-12FCKeditor 插件開發(fā) 示例(詳細(xì)版本)
2009-06-06網(wǎng)頁編輯器FCKeditor 2.6.4精簡配置方法
今天看到網(wǎng)上有人問asp中FCKeditor的配置方法,特整理了一些文檔方便需要的朋友2012-03-03fckeditor常用Js,獲取fckeditor內(nèi)容,統(tǒng)計fckeditor字?jǐn)?shù),向fckeditor寫入指定代碼
fckeditor常用Js,獲取fckeditor內(nèi)容,統(tǒng)計fckeditor字?jǐn)?shù),向fckeditor寫入指定代碼2010-08-08