锘钧(function ($) { var plugin = {}; var defaults = { tiptxt: "宸茶秴鍑哄瓧鏁伴檺鍒讹紒" }; $.fn.xhrtextares = function (options) { var textares = {}; var el = this; plugin.el = this; var init = function () { textares.settings = $.extend({}, defaults, options); el.find("textarea").bind("focus blur keydown keyup change input propertychange", function (e) { var total_len = getStrLength($(this).val()); var max_word = $(this).data("max-word"); //console.log(total_len); el.find(".tip-i").text(max_word - total_len); }) } var getStrLength = function (sStr) { // 鑾峰彇瀛楃闀垮害 锛堜互涓枃瀛楃闀垮害涓哄熀鍑嗭級 var aMatch = sStr.match(/[^\x00-\x80]/g), strlen = (sStr.length + (!aMatch ? 0 : aMatch.length)); return strlen = Math.ceil(strlen / 2); } init(); } })(jQuery);