


js code to limit the input string length of each line of textarea_form special effects
But textarea does not have this attribute.
The server-side textbox attribute of asp.net does not work, so we can only use js script to control it
Okay, without further ado, let’s start with the code
javascipt source code:
function textCounter(field, maxlimit, lines) {//Parameter description: field is a textarea object, maxlimit is the maximum allowed length, lines is the number of lines
var arr = field.value.split("n");//First we need to verify the number of lines by branching symbol" ”
var perLine = "";
var value = "";
if (arr.length < lines) lines = arr.length; // Determine whether the number of lines exceeds the number of lines we specify , if it exceeds, change the number of lines to the exceeded, because we need to calculate the string length
for (loop = 0; loop < lines; loop ) {//Loop to measure the total length of the string, not much to say
perLine = arr[loop];
if (perLine.length > maxlimit)
perLine = perLine.substring(0, maxlimit);
value = value perLine;
if ( loop != lines - 1)
value = value "n";
}
if (field.value != value)
field.value = value;
if (checkstr(value , maxlimit)) {//Determine whether the string length exceeds the standard
field.value = value.substring(0, maxlimit);//Delete the excess string
}
}
function showOverWords(obj, maxlength) {//Display the remaining number of input characters obj is a txteara object, maxlength maximum length
len = obj.value.length;
$("#wordCount"). html(maxlength - len); //This sentence is from jquery, you can change it yourself. It means modifying the value of id to wordCount tag
}
function checkstr(str, digit) {// Determine whether the length of the string exceeds the standard in Chinese and English
var n = 0;
for (i = 0; i < str.length; i ) {
var leg = str.charCodeAt(i) ;//ASCII code
if (leg > 255) {//Anything greater than 255 is Chinese
n = 2;//If it is Chinese, it is 2 bytes
} else {
n = 1;//English, not much to say
}
}
if (n > digit) {
return true;
} else {
return false;
}
}
ok There are three functions above. We can achieve the functions we want by calling these three functions.

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



PHP function introduction—strlen(): Get the length of a string In PHP development, we often need to get the length of a string to perform various operations. PHP provides a very practical function strlen() to get the length of a string. This article will introduce you to the usage of this function and give some sample code. The syntax of the strlen() function is as follows: intstrlen(string$string) It accepts one parameter, which is the string to get the length,

Java string length refers to the number of characters in a character object. In java, each character has a Unicode value, and a java string is a sequence of Unicode characters. Therefore, the length of a Java string is calculated by the number of Unicode characters in the string object. Java string is one of the most commonly used data types in the Java language and can be used to store text data.

You can use the readonly attribute, disabled and readwrite attributes to set the textarea read-only. Detailed introduction: 1. readonly attribute, the value of the readonly attribute is readonly; 2. disabled attribute, the content of the <textarea> element cannot be changed, because the value of the disabled attribute is disabled; 3. readwrite attribute, the content of the <textarea> element can Changes and more.

Python's len() function: Get the length of a list or string, you need specific code examples 1. Introduction In Python programming, the len() function is a very commonly used built-in function, used to get lists, tuples, and strings. The length of the data type. This function is very simple and convenient and can help us process data more efficiently. This article will introduce the usage of len() function in detail and give some specific code examples. 2. Usage of len() function The len() function is used to return the length of a given object.

How to use the LEN function to count the length of a string requires specific code examples. In programming, you often encounter situations where you need to count the length of a string. In this case, you can use the LEN function to achieve this. The LEN function is a commonly used string function. It can return the number of characters in a given string and is very convenient and practical. The following will introduce how to use the LEN function to count the length of a string and give specific code examples. First, we need to understand the basic usage of the LEN function. The syntax of the LEN function is as follows: LEN(strin

Python's len() function: Get the length of a string, specific code examples are required. As an easy-to-learn and powerful programming language, Python provides many convenient functions and methods for string operations. Among them, the len() function is a commonly used function used to obtain the length of a string. In this article, we will explore the usage of the len() function and provide some concrete code examples. First, let's look at the basic usage of the len() function. The len() function accepts a string as

In PHP development, it is often necessary to calculate the length of strings. PHP provides a built-in function mb_strlen(), which is used to calculate the length of a string, especially suitable for processing Chinese characters. In PHP, the length of a string can be obtained using the strlen() function. However, this function has problems with statistics on strings containing non-ASCII characters (including Chinese). Since strlen() is calculated based on the number of bytes occupied by each character, in some encoding methods, Chinese characters

The strlen() function is a built-in function in PHP used to obtain the character length of a string. In many PHP projects, the length of the string is very important data, and the strlen() function becomes very useful at this time. Next, let us introduce how to use the strlen function in PHP to get the string length. 1. Basic syntax The basic syntax of the strlen() function is very simple. You only need to pass the string whose length you want to obtain as a parameter to the function. The specific format is as follows: <?
