Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:00:27915browse
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!
}
}


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