search
HomeWeb Front-endJS Tutorialjs 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:

Copy code The code is as follows:

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 for (loop = 0; loop 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 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.
Statement
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
java字符串长度是什么java字符串长度是什么Jul 10, 2023 pm 01:29 PM

java字符串长度是指一个字符对象中字符的数量。在java中,每个字符都有一个Unicode值,而java字符串是由Unicode字符组成的序列。因此,java字符串长度的计算方式就是该字符串对象中Unicode字符的数量。java字符串是java语言中最常用的数据类型之一,可以用来存储文本数据。

Python的len()函数:获取列表或字符串的长度Python的len()函数:获取列表或字符串的长度Nov 18, 2023 am 09:23 AM

Python的len()函数:获取列表或字符串的长度,需要具体代码示例一、介绍在Python编程中,len()函数是一个非常常用的内建函数,用于获取列表、元组、字符串等数据类型的长度。这个函数非常简单和方便,可以帮助我们更加高效地处理数据。本文将详细介绍len()函数的用法,并给出一些具体的代码示例。二、len()函数的用法len()函数用于返回给定对象的长

PHP函数介绍—strlen(): 获取字符串的长度PHP函数介绍—strlen(): 获取字符串的长度Jul 24, 2023 am 09:03 AM

PHP函数介绍—strlen():获取字符串的长度在PHP开发中,我们经常需要获取字符串的长度,来进行各种操作。PHP提供了一个非常实用的函数strlen()来获取字符串的长度。本文将向大家介绍这个函数的用法,并给出一些示例代码。strlen()函数的语法如下:intstrlen(string$string)它接受一个参数,即要获取长度的字符串,

用LEN函数计算字符串的长度方法用LEN函数计算字符串的长度方法Jan 28, 2024 am 08:49 AM

如何使用LEN函数统计字符串长度,需要具体代码示例在编程中,经常会遇到需要统计字符串长度的情况,这时可以使用LEN函数来实现。LEN函数是一种常用的字符串函数,它可以返回给定字符串的字符个数,非常方便实用。下面将会介绍如何使用LEN函数来统计字符串长度,并给出具体的代码示例。首先,我们需要了解LEN函数的基本使用方法。LEN函数的语法如下:LEN(strin

怎么设置textarea只读怎么设置textarea只读Sep 28, 2023 am 11:17 AM

可以使用readonly属性、disabled和readwrite属性来设置textarea只读。详细介绍:1、readonly属性,readonly属性的值为readonly;2、disabled属性,<textarea>元素的内容将无法更改,因为disabled属性的值为disabled;3、readwrite属性,<textarea>元素的内容可以更改等等。

Python的len()函数:获取字符串的长度Python的len()函数:获取字符串的长度Nov 18, 2023 pm 12:11 PM

Python的len()函数:获取字符串的长度,需要具体代码示例Python作为一种简单易学且功能强大的编程语言,在字符串操作方面提供了许多便利的函数和方法。其中,len()函数是一个常用的函数,用于获取字符串的长度。在本文中,我们将探讨len()函数的用法,并提供一些具体的代码示例。首先,让我们来看看len()函数的基本用法。len()函数接受一个字符串作

如何使用PHP中的strlen函数获取字符串长度如何使用PHP中的strlen函数获取字符串长度Jun 26, 2023 pm 12:36 PM

strlen()函数是PHP中的一个内置函数,用于获取字符串的字符长度。在许多php项目中,字符串的长度是很重要的数据,这时strlen()函数就变得非常实用了。下面,让我们来介绍如何使用PHP中的strlen函数获取字符串长度。1.基本语法strlen()函数的基本语法是非常简单的,只需要将要获取长度的字符串作为参数传递给函数即可。具体格式如下:&lt;?

字符串长度包括\0吗字符串长度包括\0吗Jun 28, 2023 am 11:46 AM

字符串长度包括\0字符,在C语言中,字符串是由字符数组组成的,以\0作为结尾,这个\0字符用来表示字符串的结束,所以,字符串的长度就是字符数组中字符的个数,包括最后的\0字符。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),