jQuery write textarea input word limit code

The example of this article shared the specific code of jQuery Textarea input word limit for everyone, for your reference, the specific content is as follows

  // Judgment the browser is not evil IE var bind_name = 'input'; // Default Event IF (Navigator.USERAGENT.INDEXOF ("msie")! = -1) {bind_name = 'propertyChange'; // Don't face IE exclusive event} var maxlength = 10 ; // Limited the input word number $ ('# comment'). Bind (bind_name, function () {// Binding the TEXTAREA Binding event VAR Strlen = $ (this) .val (). Replace (/ [^ \ x00- \ XFF] / g, "aa"). Length; // Read the conversion to get the length, Chinese conversion to 2 lengths, English empty ignore 1 length $ ('# aviablecount'). Text (function () {//// A SPAN Display Now how long IF (Math.ceil (Strlen / 2)> maxlength) {// exceeds the limit length, only the maximum number returnometh;} else {return Math.ceil (Strlen / 2); // Why is it divided by 2, because the Chinese counts two lengths, here we have to turn back, 0.5 Chinese length calculates 1 Chinese length}}); if (strlen> Maxlength * 2) {// input exceed the maximum length, Intercede for 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;
          }
        }
      }
    })
    
The above is all the content of this article, I hope to everyone Learning is helpful, I also hope that everyone will support Tumi Cloud.


© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment