var bind_name = 'input';
if (navigator.userAgent.indexOf("MSIE") != -1) {
bind_name = 'propertychange';
}
var maxlength = 10;
$('#Comment').bind(bind_name, function () {
var strlen = $(this).val().replace(/[^x00-xff]/g, "aa").length;
$('#aviableCount').text(function () {
if (Math.ceil(strlen / 2) > maxlength) {
return maxlength;
}
else {
return Math.ceil(strlen / 2);
}
});
if (strlen > maxlength * 2) {
for (i = 1; i > 0; i++) {
$(this).val($(this).val().substr(0, $(this).val().length - 1)); if ($(this).val().replace(/[^x00-xff]/g, "aa").length <= maxlength * 2) {
break;
}
}
}
})
|