


ASP.NET jQuery Example 13 Original jQuery text box character limit plug-in-TextArea Counter_jquery
•Can limit the maximum input character length
•Can set the character interception speed
•Customizable prompt information text style (customized text content can be improved)
This plug-in counts that the length of English characters and Chinese characters are the same .
Without further ado, here is the detailed plug-in code. The specific implementation details are already commented in the code:
; (function ($) {
$.fn.extend({
textAreaCount: function (options) {
var $textArea = this;
options = $.extend({
maxlength: 140, // Define a maximum input length variable, initialized to 500
speed: 15, // Define the speed variable for deleting characters
msgstyle: "font -family:Arial;font-size:small;color:Gray;small;text-align:right;margin-top:3px;", // Prompt information display style
msgNumStyle: "font-weight:bold;color :Gray;font-style:italic;font-size:larger;" // The remaining length style in the prompt message
}, options);
var $msg = $("");
// Dynamically load a prompt information container behind the text box
$textArea.after($msg);
// Add keypress event Used to determine whether the current content can still be input
$textArea.keypress(function (e) {
// 8 is the Backspace button, 46 is the Delete button
// If the current input character length is 0 , and the key value is not 8 and 46, no operation will be performed
if ($textArea.val().length >= options.maxlength && e.which != '8' && e.which != '46 ') {
e.preventDefault();
return;
}
}).keyup(function () { // Add keyup event to calculate the remaining input words and display
var curlength = this.value.length;
$msg.html("").html("You can also enter " (options.maxlength - curlength) "< ;/span>Word");
var init = setInterval(function () {
// If the input content is greater than the set maximum length, the content will be automatically intercepted at the set speed
if ($textArea. val().length > options.maxlength) {
$textArea.val($textArea.val().substring(0, options.maxlength));
$msg.html("").html ("You can also enter" options.maxlength "words");
}
else {
clearInterval(init);
}
}, options.speed);
}).bind("contextmenu", function (e) { // Disable the right mouse button to prevent text manipulation through the mouse
return false;
});
// When loading for the first time, you can now enter the character length prompt information
$msg.html("").html("You can also enter " options.maxlength "Word");
return this;
}
});
})(jQuery);
directly Copy and save the above code to jquery.textareacounter.js.
Demo:
Now let’s take a look at how to use the plug-in. First, we must reference the plug-in. The code is as follows:
Page structure Code:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Onenote is one of the best note-taking tools offered by Microsoft. Combined with Outlook and MSTeams, Onenote can be a powerful combination for increasing productivity at work and in personal creative productivity. We have to take notes in a different format, which may be more than just writing things down. Sometimes we need to copy images from different sources and do some editing in our daily work. Images pasted on Onenote can go a long way if you know how to apply the changes. Have you ever encountered a problem when using Onenote that images pasted on Onenote cannot allow you to work easily? This article will look at using images effectively on Onenote. we can

How to hide text before any click in PowerPoint If you want text to appear when you click anywhere on a PowerPoint slide, setting it up is quick and easy. To hide text before clicking any button in PowerPoint: Open your PowerPoint document and click the Insert menu. Click on New Slide. Choose Blank or one of the other presets. Still in the Insert menu, click Text Box. Drag a text box onto the slide. Click the text box and enter your

How to Make a Calendar in Word Using Tables If you want to create a calendar that fits your specifications exactly, you can do everything from scratch using tables in Word. This allows you to design the exact layout you want for your calendar. Create a calendar using tables in Word: Open a new Word document. Press Enter a few times to move the cursor down the page. Click the Insert menu. In the ribbon, click the table icon. Click and hold the upper left square and drag out a 7×6 table. Write the day of the week on the first line. Use another calendar as a reference to fill in the days of the month. Highlight any date outside the current month. In the main menu, click the text color icon and select Gray. For the current month, start with

In this article, we will learn how to limit the number of characters allowed in a form input text field. We use tags to get user input in HTML. To give a limit (or range) to an input field, we use the min and max attributes to specify the maximum and minimum values of the input field, respectively. To set the maximum character limit in an input field, we use the maxlength attribute. This property specifies the maximum number of characters for the input field. To set the minimum character limit in an input field, we use the minlength attribute. This property specifies the minimum number of characters for the input field. First, let's look at how to set the maximum character limit of an input field - Syntax Here is the syntax for setting the maximum character limit of an input field. <inpu

HTML text box types include single line text box, password text box, number text box, date text box, time text box, file upload text box, multi-line text box, etc. Detailed introduction: 1. The single-line text box is the most common type of text box, used to accept single-line text input. The user can enter any text in the text box, such as user name, password, email address, etc.; 2. The password text box is used To accept password input, when the user enters the password, the content in the text box will be hidden to protect the user's privacy; 3. Numeric text box, etc.

To add a newline character to an HTML text area, we can use the HTML newline tag to insert a newline character anywhere. Alternatively, we can also use the CSS property "white-space:pre-wrap" to automatically add line breaks to the text. This is particularly useful when displaying preformatted text in a text area. So let’s discuss ways to add line breaks. Method creates a text area in HTML and assigns it an id. Create a button that, when clicked, will split the text of the text area using line breaks. Now create a function that separates text into newlines. The code of this function is -functionreplacePeriodsWithLineBreaks()

Title: How to write HTML text box code with scroll bar The text box in HTML is one of the commonly used user input controls. In some cases, when the text content is too long, the text box will be displayed incompletely. At this time, we can add a scroll bar to the text box to support scrolling. This article will introduce in detail how to write HTML text box code with scroll bar effect, and give specific code examples. 1. Use the textarea element to create a text box. In HTML, we use the textarea element to create a text box.

How to set the text box border to be transparent: 1. Open the document, select the inserted text box, right-click and select "Format Object"; 2. In the pop-up box on the right, select "Shape Options" - "Fill and Line" - "Transparency" ”; 3. Adjust the transparency as needed.
