Fckeditor編輯器內容長度限制統(tǒng)計實現(xiàn)方法
更新時間: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="檢測字數(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當前: "+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; //最大輸入字數(shù)
content= $(editor.EditorDocument.body).text();
var len= content.length;
var $info =$('#info');//存放提示信息
if(len < maxLength){
.text("還可以輸入 "+(maxLength-len)+"字");
}
if(len == maxLength){
$info.text("字數(shù)達到上限");
}
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="檢測字數(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當前: "+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; //最大輸入字數(shù)
content= $(editor.EditorDocument.body).text();
var len= content.length;
var $info =$('#info');//存放提示信息
if(len < maxLength){
.text("還可以輸入 "+(maxLength-len)+"字");
}
if(len == maxLength){
$info.text("字數(shù)達到上限");
}
if(len > maxLength){
$info.text(" 輸入字符超過"+maxLength+"個,請更改!");
}
}
FCKeditor_OnComplete()
}
您可能感興趣的文章:
- FCKEditor超級鏈接默認新窗口打開的修改方法
- Smarty中調用FCKeditor的方法
- fckeditor編輯器下的自定義分頁符實現(xiàn)方法
- FCKeditor編輯器添加圖片上傳功能及圖片路徑問題解決方法
- ThinkPHP中FCKeditor編輯器的使用方法
- fckeditor編輯器在php中的配置方法
- FCKeditor 圖片上傳進度條不動的解決方法
- php在頁面中調用fckeditor編輯器的方法
- 瀏覽器執(zhí)行history.go(-1) FCKeditor編輯框內顯示html源代碼的解決方法
- FCK編輯器(FCKEditor)添加新按鈕和功能的修改方法
- fckeditor粘貼Word時彈出窗口取消的方法
相關文章
在kindEditor中獲取當前光標的位置索引的實現(xiàn)代碼
一直在用KindEditor,今天要用到光標的位置,然后就gg一下辦法,后來發(fā)現(xiàn)這東西的編輯區(qū)域居然是iframe里面的一個body,不是textarea/input,后來就翻開了他的代碼看,發(fā)現(xiàn)有個insertHtml2011-11-11syntaxhighlighter 去掉右上角問號圖標的三種方法
syntaxhighlighter可以高亮著色顯示幾乎所有語言形式的源代碼,還可以顯示行號,是一款深受網站建設人員喜愛的工具,并且它還是免費的2013-11-11CKeditor與syntaxhighlight打造joomla代碼高亮
最近在用csdn和cnblogs發(fā)帖子和寫隨筆的時候,發(fā)現(xiàn)了好多的IT的網站或者和代碼有關系的一些論壇,博客之類,他們都有一個非常好的語法高亮!很強大!2010-07-07fckeditor常用Js,獲取fckeditor內容,統(tǒng)計fckeditor字數(shù),向fckeditor寫入指定代碼
fckeditor常用Js,獲取fckeditor內容,統(tǒng)計fckeditor字數(shù),向fckeditor寫入指定代碼2010-08-08