Home  >  Article  >  Web Front-end  >  Limit the number of text bytes js code_form effects

Limit the number of text bytes js code_form effects

WBOY
WBOYOriginal
2016-05-16 19:18:08993browse

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:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn