Home  >  Article  >  Web Front-end  >  Text box word limit function jquery plug-in_jquery

Text box word limit function jquery plug-in_jquery

WBOY
WBOYOriginal
2016-05-16 18:41:151120browse

Later, when I was wandering around on the Internet, I suddenly found a better jquery plugin with character limit for text boxes. It is simple and easy to use. >Copy code

Text box word limit function jquery plug-in_jquery The code is as follows:

< head> About the character limit function of the text box

< ;p>Enter your hobbies (<50 characters)




< /div>

Enter your postal code (<6 characters)







Attribute explanation:

data-maxsize: the The maximum number of words that the text field can accept. (important)
data-output: If you want to dynamically display the number of words in the text box in real time, this attribute sets the ID of the span or div that displays the number of words. (The color of the word number display will change with the number. Change)
If you do not modify its source file, after adding the js reference, you only need to add the data-maxsize attribute to your text or textarea.
About dynamically setting the maximum value
Use the setformfieldsize method:
setformfieldsize($field, maxsize, outputfieldid)
Attribute explanation:
$field: is the JQuery object of the restricted text box (reference Jquery document).
maxsize: Same as data-maxsize, the maximum number of words that the text field can accept.
outputfieldid: Same as data-output.
Example:




Copy code


The code is as follows:
Executed when the interface is loaded.
Demo code download
http://xiazai.jb51.net/200911/yuanma/textarea_maxlength.rar
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