此方法支持IE 不支持火狐。可能是因為FCKEidtor的keyup方法在火狐下不被支持。
FCKEditor編輯器換為TextBox,應該就沒有問題了。
前臺:
復制代碼 代碼如下:
tr>
th>
短敘述
br />
(限100中文字)br />
當前文字個數: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("當前已經達到100中文字,請不要繼續輸入!");
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個字符數 提示
點擊【確定】后 自動截取100個字符

您可能感興趣的文章:- linux下wc統計文件的個數、行數、字數、字節數等信息方法
- C++統計中英文大小寫字母、數字、空格及其他字符個數的方法
- C語言編程中統計輸入的行數以及單詞個數的方法
- c++統計文件中字符個數代碼匯總
- C語言統計字符個數代碼分享
- C語言統計一串字符中空格鍵、Tab鍵、回車鍵、字母、數字及其他字符的個數(Ctrl+Z終止輸入)