Home > Web Front-end > JS Tutorial > JavaScript implements limiting the number of words when writing characters in a text field_javascript skills

JavaScript implements limiting the number of words when writing characters in a text field_javascript skills

WBOY
Release: 2016-05-16 17:00:27
Original
974 people have browsed it
Copy code The code is as follows:












< script>
function sum(){
var str =document.getElementById("text");
var cont=str.value;
var len=cont.length;
document. getElementById("span").innerHTML="You have currently entered " len " characters";
if(len>=100){alert("You can no longer write, the limit has been reached!");
document.getElementById("text").value=cont.substr(0,99);
//Achieve the maximum limit of 100 words. If it exceeds, no more data will be written!
}
}


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