JQuery extension implementation text prompt how many bytes can be input this article describes how many bytes can be input for jQuery extension implementation text prompt. We will share this with you for your reference. The details are as follows:
1. Add jQuery custom Extension
$ (Function ($) {// tipWrap: the container that prompts the message // maxNumber: maximum input character $. fn. artTxtCount = function (tipWrap, maxNumber) {var countClass = 'js _ txtCount ', // defines the CSS Class Name of the internal container fullClass = 'js _ txtFull ', // define the name of the CSS class that exceeds the character disabledClass = 'Disabled '; // define the CSS Class Name of the unavailable submit button // count the number of words var count = function () {var val = lenFor ($. trim ($ (this ). val (); if (val <= maxNumber) {tipWrap.html ('\ u8FD8 \ u80FD \ u8F93 \ u5165'+ (MaxNumber-val) +'\ U4E2A \ u5B57 \ u8282 ');} else {tipWrap.html (' \ u5DF2 \ u7ECF \ u8D85 \ u51FA'+ (Val-maxNumber) +'\ U4E2A \ u5B57 \ u8282 ') ;};$ (this). bind ('keyup change', count); return this ;};});
Function for obtaining the number of bytes
var lenFor = function(str){ var byteLen=0,len=str.length; if(str){ for(var i=0; i
255){ byteLen += 3; } else{ byteLen++; } } return byteLen; } else{ return 0; }}
2. instantiation