複製程式碼 代碼如下: 也可輸入140字 <BR> var txtobj = {<BR> divName: "area", //外層容器的類< /textarea的class<BR> numName: "num", //數字的class<BR> num: 140 //數字的最大數目<BR> //定義變數<BR> var $onthis; //指向目前<BR> var $divname = txtobj.divName; //外層容器的類型< var $numName = txtobj.numName; //數字的class<BR> var $num = txtobj.num; //數字的最大數目<BR> reCh = /[u00-uff]/;<BR> return !reCh.test(str);<BR> }<BR> var strlen = 0; //初始定義長度為0<BR> var txtval = $.trim($onthis.val());<BR> for (var i = 0; i < txtval.length; i ) {< == true) {<BR> strlen = strlen 2; //中文為2個字元<BR> } strlen = strlen 1; // strlen = strlen 1; // strlen = Math.ceil(strlen / 2); //中英文相加除2取整數<BR> if ($num - strlen < 0) {<BR> ;font-weight:lighter' class=" $numName ">" Math.abs($num - strlen) " 字"); //超出的樣式<BR> $par.html("還可輸入<b class=" $numName ">" ($num - strlen) "字"); //正常時候<BR> }< $num - strlen);<BR> }<BR> $("." $textareaName).live("focus", function () {<BR> ). ).find("." $numName); //取得目前的數字<BR> $par = $b.parent();<BR> var setNum = setInterval(numChange, 500);<BR> });<BR> }<BR> textareaFn();<BR>