弘帝企业智能建站系统交流平台

 找回密码
 立即注册
查看: 2546|回复: 0

富文本框限制输入字数函数

[复制链接]
发表于 2018-5-9 16:45:00 | 显示全部楼层 |阅读模式
该函数在个人版本路径:Login/js/common.js
function textLimitCheck(thisArea, maxLength){
        if (thisArea.value.length > maxLength){
                alert(maxLength + ' 个字限制. \r超出的将自动去除.');
                thisArea.value = thisArea.value.substring(0, maxLength);
                thisArea.focus();
    }
    if ($(thisArea).next().attr('class')=='tip'){
        $(thisArea).next().find(".count").html(thisArea.value.length);
    }else{
        $(thisArea).after('<div class="tip">限 '+ maxLength +' 个字符,已输入 <span class="count">'+ thisArea.value.length +'</span> 个字</div>');
    }
}

调用方法:
1、引用common.js
2、在textarea中增加 onkeyUp="textLimitCheck(this,500)"
经过多次优化后,以上2步即可,不需要额外增加其它任何脚本。

案例:/login/template/script/default.zhg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|弘帝企业智能建站系统 ( 皖ICP备07503252号 )

GMT+8, 2024-4-19 13:14 , Processed in 0.113644 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表