FCKEidtor 自動統(tǒng)計輸入字符個數(shù)(IE)
更新時間:2009年05月29日 20:43:16 作者:
由于項目需要,需要做字數(shù)統(tǒng)計,于是寫了一個JS計算字符個數(shù),如果輸入的字符數(shù)大于100個字符,就彈出提示,點擊【確定】后,自動截取為100個字符。
此方法支持IE 不支持火狐??赡苁且驗镕CKEidtor的keyup方法在火狐下不被支持。
FCKEditor編輯器換為TextBox,應(yīng)該就沒有問題了。
前臺:
<tr>
<th>
短敘述
<br />
(限100中文字)<br />
當(dāng)前文字個數(shù):<asp:Label ID="lblShowTextLength" runat="server" Text="0" ForeColor="Red"></asp:Label><br />
</th>
<td style="text-align: left;">
<FCKeditorV2:FCKeditor ID="fckPrdDescription" runat="server" Height="240px" Width="100%">
</FCKeditorV2:FCKeditor>
</td>
</tr>
JS代碼:
<script type="text/javascript">
function FCKeditor_OnComplete(editorInstance)
{
var oEditor = FCKeditorAPI.GetInstance('fckPrdDescription');
oEditor.EditorDocument.body.onkeyup=function ()
{
if( document.all)
{
$("lblShowTextLength").innerText =oEditor.EditorDocument.body.innerText.length;
}
else
{
var r = oEditor.EditorDocument.createRange() ;
r.selectNodeContents( oEditor.EditorDocument.body ) ;
$("lblShowTextLength").innerText= r.toString().length ;
}
if(parseInt($("lblShowTextLength").innerText)>100)
{
alert("當(dāng)前已經(jīng)達到100中文字,請不要繼續(xù)輸入!");
oEditor.EditorDocument.body.innerText=oEditor.EditorDocument.body.innerText.substring(0,100);
$("lblShowTextLength").innerText =oEditor.EditorDocument.body.innerText.length;
}
// $("ddd").value =oEditor.EditorDocument.body.innerHTML;
}
if (document.getElementById("hidStatus").value=="Cancel")
{
editorInstance.EditorDocument.designMode="off";
}
}
</script>
演示:
輸入多馀100個字符數(shù) 提示
FCKEditor編輯器換為TextBox,應(yīng)該就沒有問題了。
前臺:
復(fù)制代碼 代碼如下:
<tr>
<th>
短敘述
<br />
(限100中文字)<br />
當(dāng)前文字個數(shù):<asp:Label ID="lblShowTextLength" runat="server" Text="0" ForeColor="Red"></asp:Label><br />
</th>
<td style="text-align: left;">
<FCKeditorV2:FCKeditor ID="fckPrdDescription" runat="server" Height="240px" Width="100%">
</FCKeditorV2:FCKeditor>
</td>
</tr>
JS代碼:
復(fù)制代碼 代碼如下:
<script type="text/javascript">
function FCKeditor_OnComplete(editorInstance)
{
var oEditor = FCKeditorAPI.GetInstance('fckPrdDescription');
oEditor.EditorDocument.body.onkeyup=function ()
{
if( document.all)
{
$("lblShowTextLength").innerText =oEditor.EditorDocument.body.innerText.length;
}
else
{
var r = oEditor.EditorDocument.createRange() ;
r.selectNodeContents( oEditor.EditorDocument.body ) ;
$("lblShowTextLength").innerText= r.toString().length ;
}
if(parseInt($("lblShowTextLength").innerText)>100)
{
alert("當(dāng)前已經(jīng)達到100中文字,請不要繼續(xù)輸入!");
oEditor.EditorDocument.body.innerText=oEditor.EditorDocument.body.innerText.substring(0,100);
$("lblShowTextLength").innerText =oEditor.EditorDocument.body.innerText.length;
}
// $("ddd").value =oEditor.EditorDocument.body.innerHTML;
}
if (document.getElementById("hidStatus").value=="Cancel")
{
editorInstance.EditorDocument.designMode="off";
}
}
</script>
演示:
輸入多馀100個字符數(shù) 提示

點擊【確定】后 自動截取100個字符
相關(guān)文章
FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合
FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合方法,里面有下載,可以根據(jù)需要結(jié)合自己的fckeditor版本。2010-04-04fckeditor在php中的用法(添加于修改寫成了函數(shù))
這里就不多說了,看代碼。后面有說明。2009-12-12CKEditor中加入syntaxhighlighter代碼高亮插件
CKEditor是新一代的FCKeditor,是一個重新開發(fā)的版本。CKEditor是全球最優(yōu)秀的網(wǎng)頁在線文字編輯器之一,因其驚人的性能與可擴展性而廣泛的被運用于各大網(wǎng)站2014-12-12編輯器中designMode和contentEditable的屬性的介紹
先解釋一下在線編輯器的原理:首先需要IE5.0以上版本的支持.因為IE5.0以上版本有一個編輯狀態(tài),designMode是document的屬性,意思是設(shè)置或獲取表明文檔是否可被編輯的值,默認值為off或Inherit2008-11-11百度UEditor修改右下角統(tǒng)計字數(shù)包含html樣式
百度UEditor修改右下角統(tǒng)計字數(shù)默認只統(tǒng)計前臺所見的文字個數(shù),如何讓右下角統(tǒng)計字數(shù)包含html樣式,需要的朋友可以參考下2014-07-07