Home >Web Front-end >JS Tutorial >Limit the number of text bytes js code_form effects
When working on a project, I write a piece of js for everyone. Regarding the problem of limiting the number of characters in text, it is often used in actual development; the main problem occurs in the restriction of Chinese. The following code solves the verification problem of limiting the number of bytes; just save this code to a js file and Introduce it into the verification page and you can use it! At the same time, I hope you will give me your strong support and valuable opinions. I will publish more good articles in my spare time in the future, thank you! !
/*
value: value;
byteLength: database byte length
title: field Chinese name
attribute: attribute name
Usage instructions:
Add (1) onkeyup="limitLength(this.value,100,'name','name')"
(2) id="name" or [struts tag] styleId="name"
Note: The id name and attribute name must be the same
Example: