天天看點

實時統計輸入字元數

實時統計輸入字元數

實時統計輸入字元數
<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>

如圖所示

實時統計輸入字元數

繼續閱讀