close
function calculate(str,limit) {
String.prototype.lenB = function () { return this.replace(/[^\x00-\xff]/g, "**").length; }
if (str.lenB() > limit)
return false;
else
return true;
}
function calculate(){
String.prototype.lenB =function(){returnthis.replace(/[^\x00-\xff]/g,"**").length;}
//var str = "這是一個可以將漢字計算成兩個位元組的函數";
var str =document.all.uInput.value
alert("老的演算法 = "+ str.length);
alert("新的演算法 = "+ str.lenB());
}
http://codex.wiki/post/191280-944
全站熱搜