程序员

FCKEidtor 自动统计输入字符个数(IE)

作者:admin 2021-04-23 我要评论

此方法支持IE 不支持火狐。可能是因为FCKEidtor的keyup方法在火狐下不被支持。 FCKEditor编辑器换为TextBox,应该就没有问题了。 前台: 复制代码 代码如下: tr ...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)
此方法支持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個字符


本文转载自网络,原文链接:https://m.jb51.net/article/18333.htm

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 安卓版谷歌 Chrome 浏览器已支持“冻结

    安卓版谷歌 Chrome 浏览器已支持“冻结

  • 免费开源!经典压缩软件7-Zip首次登陆L

    免费开源!经典压缩软件7-Zip首次登陆L

  • Google确认Chrome 89新版:大幅减少内

    Google确认Chrome 89新版:大幅减少内

  • 鸿蒙第三方组件*SwipeCaptcha滑动拼图

    鸿蒙第三方组件*SwipeCaptcha滑动拼图