|
发表于 2013-5-24 14:17:19
|
显示全部楼层
$('#text').bind("blur focus keydown keypress keyup", function(event){
var val = $(this).val();
var len = 0;
for (var i = 0; i < val.length; i++) {
if (val[i].match(/[^\x00-\xff]/ig) != null) //全角
len += 2; //如果是全角,占用两个字节
else
len += 1; //半角占用一个字节
}
alert(len);
}); |
|