惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
U
Unit 42
N
Netflix TechBlog - Medium
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
小众软件
小众软件
V
Visual Studio Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
GbyAI
GbyAI
爱范儿
爱范儿
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
博客园_首页
D
Docker
A
About on SuperTechFans
G
Google Developers Blog
I
InfoQ
T
The Blog of Author Tim Ferriss
V
V2EX
博客园 - Franky

博客园 - 神话

C#的float型,竟然与SQL中float型不对应(转载) 【源码】非常有用的Vml图像画板(收藏) 为Html 的Select 加一个提示语和输入方法(转载) asp.net三色交替的下拉列表框(转载) 常用正则表达式(收藏) ListBox控件上移、下移操作(Ajax) 客户端实现PadLeft 获取某行的字段ID值(GridView模板列) 日历控件收藏 我的博客地图脚本代码 我的博客地图特效 生成html页面 初次使用ZedGraph 梅花雪日历控件(网络收藏) 树型菜单<仿QQ型菜单>(网络收藏) 面向对象分析(网络收藏) 常用正则表达式(收集)及使用方法 三层架构(非原创) 网页常用代码小技巧五(网络收藏)
实时统计输入字符数
神话 · 2007-06-09 · via 博客园 - 神话

 从QQ空间上抠出来的一段代码,用于实时统计输入字符数

<script>
    
var $E = document.getElementById;
String.prototype.lenB 
= function(){
    
return this.unHtmlReplace().replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**").length;
}

String.prototype.unHtmlReplace 
= function () {
    
var s = (this).replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&nbsp;/g," ").replace(/&quot;/g,"\"");
    return s.replace(/&#(\d{2});/g,function($0,$1) {return unescape(
"%"+parseInt($1).toString(16));});
}
    function onModChange(s, max, o) {    //实时显示输入字数的
    if(document.readyState != 
"complete") {
        s = escape(s);
        setTimeout('onModChange(unescape(
"'+ s+ '"),'+ max+ ',$E("'+ o.id+ '"))', 10);
        return;
    }
    var words=s.lenB();
    if(words > max)
        words = 
"<font color=red>"+ words+ "</font>";
    else
        words = 
"<font color=green>"+ words+ "</font>";
    o.innerHTML = 
"已输入"+ words+ "个字符(最多"+ max+ "个字符)";
}
</script>

<!--S 发表评论-->
<div>
    
<label><span>发表评论:</span>
 
<textarea name="content" id="cmt_content" cols="50" rows="3" onpropertychange="onModChange(this.value, 150, $E('post_status'))"></textarea>
    
</label>
    
<div><em id="post_status">已输入<font color=green>0</font>个字符(最多150个字符)</em></div>
</div>