JQuery maxlength text limit plugin

Source: Internet
Author: User


There are many ways to achieve this effect. Here we will introduce a jQuery plug-in maxlength, which is very simple to use. Let's take a look at the demo:
Jquery maxlength demo address
Package and download DEMO code
Take a look at the key code in the Demo:
1. Load maxlength. js
<Script type = "text/javascript" src = "maxlength. js"> </script>
2. Add a function. There are three examples in the Demo. You can select different functions as needed, but the last example is invalid for Chinese.
Copy codeThe Code is as follows:
$ (Function (){
$ ('Textarea. limited'). maxlength ({
'Feedback': '. charsLeft', 'useinput': true
});
$ ('Input. limited'). maxlength ({
'Feedback': '. charsLeft'
});
$ ('Textea. wordlimited'). maxlength ({
'Word': true,
'Feedback': '. wordsLeft', 'useinput': true
});
});

3. Call
Copy codeThe Code is as follows:
<Form action = "">
<P> you can enter <span class = "charsLeft"> 20 </span> characters </p>
<Textarea class = "limited"> </textarea>
<Input type = "hidden" name = "maxlength" value = "20"/>
</Form>
<Form action = "">
<P> you can enter <span class = "charsLeft"> 10 </span> characters </p>
<Input maxlength = "10" class = "limited"/>
</Form>

Some necessary explanations:
'Useinput': trueBecause textarea needs to be implemented using input, this parameter is required when you use textarea.
'Feedback': '. charsLeft'It refers to the words displayed in the class = "charsLeft" container.
InputSet the maximum value for direct useMaxlength = "10"
In textarea, you must set the value corresponding to the input value.Value = "20"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.