FCKEidtor 自動(dòng)統(tǒng)計(jì)輸入字符個(gè)數(shù)(IE)
更新時(shí)間:2009年05月29日 20:43:16 作者:
由于項(xiàng)目需要,需要做字?jǐn)?shù)統(tǒng)計(jì),于是寫(xiě)了一個(gè)JS計(jì)算字符個(gè)數(shù),如果輸入的字符數(shù)大于100個(gè)字符,就彈出提示,點(diǎn)擊【確定】后,自動(dòng)截取為100個(gè)字符。
此方法支持IE 不支持火狐??赡苁且?yàn)镕CKEidtor的keyup方法在火狐下不被支持。
FCKEditor編輯器換為T(mén)extBox,應(yīng)該就沒(méi)有問(wèn)題了。
前臺(tái):
<tr>
<th>
短敘述
<br />
(限100中文字)<br />
當(dāng)前文字個(gè)數(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)達(dá)到100中文字,請(qǐng)不要繼續(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個(gè)字符數(shù) 提示
FCKEditor編輯器換為T(mén)extBox,應(yīng)該就沒(méi)有問(wèn)題了。
前臺(tái):
復(fù)制代碼 代碼如下:
<tr>
<th>
短敘述
<br />
(限100中文字)<br />
當(dāng)前文字個(gè)數(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)達(dá)到100中文字,請(qǐng)不要繼續(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個(gè)字符數(shù) 提示
點(diǎn)擊【確定】后 自動(dòng)截取100個(gè)字符
您可能感興趣的文章:
- linux下wc統(tǒng)計(jì)文件的個(gè)數(shù)、行數(shù)、字?jǐn)?shù)、字節(jié)數(shù)等信息方法
- C++統(tǒng)計(jì)中英文大小寫(xiě)字母、數(shù)字、空格及其他字符個(gè)數(shù)的方法
- C語(yǔ)言編程中統(tǒng)計(jì)輸入的行數(shù)以及單詞個(gè)數(shù)的方法
- c++統(tǒng)計(jì)文件中字符個(gè)數(shù)代碼匯總
- C語(yǔ)言統(tǒng)計(jì)字符個(gè)數(shù)代碼分享
- C語(yǔ)言統(tǒng)計(jì)一串字符中空格鍵、Tab鍵、回車(chē)鍵、字母、數(shù)字及其他字符的個(gè)數(shù)(Ctrl+Z終止輸入)
相關(guān)文章
FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合
FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合方法,里面有下載,可以根據(jù)需要結(jié)合自己的fckeditor版本。2010-04-04
fckeditor在php中的用法(添加于修改寫(xiě)成了函數(shù))
這里就不多說(shuō)了,看代碼。后面有說(shuō)明。2009-12-12
CKEditor中加入syntaxhighlighter代碼高亮插件
CKEditor是新一代的FCKeditor,是一個(gè)重新開(kāi)發(fā)的版本。CKEditor是全球最優(yōu)秀的網(wǎng)頁(yè)在線文字編輯器之一,因其驚人的性能與可擴(kuò)展性而廣泛的被運(yùn)用于各大網(wǎng)站2014-12-12
編輯器中designMode和contentEditable的屬性的介紹
先解釋一下在線編輯器的原理:首先需要IE5.0以上版本的支持.因?yàn)镮E5.0以上版本有一個(gè)編輯狀態(tài),designMode是document的屬性,意思是設(shè)置或獲取表明文檔是否可被編輯的值,默認(rèn)值為off或Inherit2008-11-11
Office文檔在線編輯的一個(gè)實(shí)現(xiàn)方法
因?yàn)轫?xiàng)目的關(guān)系,研究了一下Office的在線編輯功能,寫(xiě)出來(lái)共享一下。2010-06-06
百度UEditor修改右下角統(tǒng)計(jì)字?jǐn)?shù)包含html樣式
百度UEditor修改右下角統(tǒng)計(jì)字?jǐn)?shù)默認(rèn)只統(tǒng)計(jì)前臺(tái)所見(jiàn)的文字個(gè)數(shù),如何讓右下角統(tǒng)計(jì)字?jǐn)?shù)包含html樣式,需要的朋友可以參考下2014-07-07


