效果图如下 : 源代码如下 : 复制代码 代码如下: <BR>$(function() { <BR>$("textarea").keyup(); <BR>}); <br><br>function strLenCalc(obj, checklen, maxlen) { <BR> var v = obj.val(), charlen = 0, maxlen = !maxlen ? 200 : maxlen, curlen = maxlen, len = v.length; <BR> for(var i = 0; i < v.length; i++) { <BR> if(v.charCodeAt(i) < 0 || v.charCodeAt(i) > 255) { <BR>curlen -= 1; <BR>} <BR>} <BR> if(curlen >= len) { <BR>$("#"+checklen).html("还可输入 <strong>"+Math.floor((curlen-len)/2)+" 个字").css('color', ''); <BR>$("#subBtn").removeAttr("disabled"); <BR>} else { <BR>$("#"+checklen).html("已经超过 <strong>"+Math.ceil((len-curlen)/2)+" 个字").css('color', '#FF0000'); <BR>$("#subBtn").attr("disabled", "disabled"); <BR>} <BR>} <BR> 还可输入 40 个汉字