JQuery extension implementation text prompt how many bytes can be input

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.