Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How many bytes does js shape?
How many bytes does js shape?
First, you should set the width of the text box, and then manually enter characters (preferably numbers) to determine how many numbers can be entered in the text box.

A number and an English letter = 1 byte.

One Chinese character = 2 bytes

With the above information: We can use js or jquery to get the text in the text box and calculate how many bytes there are in the text box.

Suppose:

Text box width = 30 pixels can actually write 10 numbers, that is, 10 bytes. If it exceeds 10, it will exceed the text box.

Assume that the number of bytes entered in the text box is 123abc.

Using js regularization, we find that the number of Chinese characters multiplied by 2 is the number of bytes occupied by Chinese characters, plus non-Chinese characters (full-angle symbols are also 2 bytes). In the last example, there are 12 bytes.

We know that > 10 characters in the current text box exceed the width of the text box.