JS to determine the number of words in Chinese limit bytes

Source: Internet
Author: User

JS Limit text bytes would have been easier to implement, the only noteworthy is the Chinese character of the judge, because the English language is not the same as the byte, English only accounted for 1 bytes, while the Chinese need 2, the following JavaScript function is usually written when the project, after a number of amendments, it should be more accurate, I'll tell you how to use it later. First comes the main function code:

Checkbyte.js Code:

Here is an example, please introduce checkbyte.js before using

Value: Values

ByteLength: Database byte length

Title: Field Chinese name

Attribute: Property Name

Instructions for use:

1, onkeyup= "Limitlength (this.value,100, ' name ', ' title ')"

2, id= "name" or "Struts Tag" styleid= "name"

Here you should note that the ID and attribute property names are the same

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.