Javascript实现真实字符串剩余字数提示的实例代码_javascript技巧
程序员文章站
2022-04-12 13:44:19
...
复制代码 代码如下:
//文本框剩余字数提示(字符大小)
function textLimitCheckSj(thisArea, maxLength, SpanId) {
var str = thisArea.value;
if (getChrLen(str, maxLength) > maxLength * 2) {
thisArea.value = str.substring(0, x-1);
}
else {
var varss = '(剩余字数:' + Math.floor((maxLength * 2 - getChrLen(str, maxLength)) / 2) + ')';
document.getElementById(SpanId).innerHTML = varss;
}
}
function getChrLen(str, maxLength) {
var realLength = 0, len = str.length, charCode = -1;
x = 0;
for (; (x charCode = str.charCodeAt(x);
if (charCode >= 0 && charCode realLength += 1;
else
realLength += 2;
}
return realLength;
}
?
推荐阅读
-
jQuery实现可收缩展开的级联菜单实例代码_javascript技巧
-
javascript下搜索子字符串的的实现代码(脚本之家修正版)_javascript技巧
-
jQuery实现可收缩展开的级联菜单实例代码_javascript技巧
-
一个JavaScript递归实现反转数组字符串的实例_javascript技巧
-
js/ajax跨越访问-jsonp的原理和实例(javascript和jquery实现代码)_javascript技巧
-
Javascript中3种实现继承的方法和代码实例_javascript技巧
-
Javascript实现动态菜单添加的实例代码_javascript技巧
-
在光标处插入字符串的实现代码 兼容IE,Firefox_javascript技巧
-
Javascript实现滚动图片新闻的实例代码_javascript技巧
-
Javascript实现动态菜单添加的实例代码_javascript技巧