Home > Web Front-end > JS Tutorial > Javascript example code to implement real string remaining character prompt_javascript skills

Javascript example code to implement real string remaining character prompt_javascript skills

WBOY
Release: 2016-05-16 17:19:23
Original
1004 people have browsed it

Copy code The code is as follows:

//The number of remaining words in the text box (character size)
function textLimitCheckSj(thisArea, maxLength, SpanId) {
var str = thisArea.value;
if (getChrLen(str, maxLength) > maxLength * 2) {
thisArea.value = str.substring (0, x-1);
}
else {
var varss = '(Number of words remaining:' Math.floor((maxLength * 2 - getChrLen(str, maxLength)) / 2) ') ';
document.getElementById(SpanId).innerHTML = varss;
}
}
function getChrLen(str, maxLength) {
var realLength = 0, len = str.length, charCode = -1;
x = 0;
for (; (x < len) && (realLength <=maxLength * 2); x ) {
charCode = str.charCodeAt(x); < ​​​​Return realLength;
} <🎜 < ;/asp:TextBox>                                                                                                                                                                                         style="color: #808080"> (within 50 words)



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