jquery统计输入框字数

$(document).ready(function(){
     $('#comment').on('input propertychange', function() {
         var count = $.trim($(this).val()).length;
         $('#tip').html("已输入 "+ count +" 个字。");
     });
 });

需要注意的是对于表情符号的字符此方法按2个字符技术,对于php的mb_strlen方法则按一个字符技术

猜你喜欢

转载自blog.csdn.net/weixin_33836223/article/details/87641846