Home > Web Front-end > JS Tutorial > jQuery maxlength text word limit plugin_jquery

jQuery maxlength text word limit plugin_jquery

WBOY
Release: 2016-05-16 18:29:19
Original
1259 people have browsed it

There are many ways to achieve this effect. Here is a jQuery plug-in maxlength. It is very simple to use. Let us take a look at the demo first:
jquery maxlength demo address
Demo code package download
Look at the key codes in the Demo:
1. Load maxlength.js

2. Add functions. There are 3 examples in the Demo. You can choose different functions according to actual needs, but the last example is invalid for Chinese.
Copy code The code is as follows:

$(function () {
$('textarea.limited' ).maxlength({
'feedback' : '.charsLeft', 'useInput' : true
});
$('input.limited').maxlength({
'feedback' : '.charsLeft'
});
$('textarea.wordLimited').maxlength({
'words': true,
'feedback': '.wordsLeft', 'useInput' : true
});
});

3. Call
Copy code The code is as follows:


You can enter 20 characters< /p>


< /form>

You can enter10 characters


< ;input maxlength="10" class="limited" />


Some necessary explanations:
'useInput' : true Because textarea needs to be implemented with input, you need this parameter when you use textarea
'feedback' : '.charsLeft' means that the number of characters displayed immediately is placed in a container with class="charsLeft "
Input Set the maximum value directly with maxlength="10"
Large values ​​in textarea need to be set to the corresponding input value value="20"

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template