I have also introduced a JQuery plug-in with similar effects, jQuery maxlength text limit plug-in. However, this charcount deployment is simpler, and it has the function of exceeding the number prompt.
Simple deployment:
1. Load js:
Copy codeThe Code is as follows:
<Script type = "text/javascript" src = "js/jquery. js"> </script>
<Script type = "text/javascript" src = "js/charCount. js"> </script>
2. Html structure:
Copy codeThe Code is as follows:
<Form id = "form" method = "post" action = "">
<H2> Default Usage <Div>
<Label for = "message"> Type your message </label>
<Textarea id = "message1" name = "message1"> </textarea>
</Div>
<H2> Custom Usage <Div>
<Label for = "message"> Another message (limited to 30, warning at 10) </label>
<Textarea id = "message2" name = "message2"> </textarea>
</Div>
</Form>
3. charCount plug-in settings:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Document). ready (function (){
// Default usage
$ ("# Message1"). charCount ();
// Custom usage
$ ("# Message2"). charCount ({
Allowed: 30,
Warning: 10,
CounterText: 'remaining words :'
});
});
</Script>
DEMO code
Package, package, and download