<script>
function String.prototype.getLength(){
var ret=this.length;
try{ret+=this.match(/[^ -~]/g).length}catch(e){}
return ret
}
alert("中文abc".getLength())
alert("中文".getLength())
alert("abc".getLength())
</script>