Js statistics enter the number of characters in the text box and limit it to no more than a few

  • 2020-03-30 03:03:38
  • OfStack

Some requirements are to more intuitively reflect how many words users can see when they input text in the text box, and some special requirements do not exceed how many words, the following is the realization:
<script src="jquery.js" type="text/javascript"></script> 
<script type="text/javascript"> 
function tjzs(){ 
var count = $("#nr").val().length; 
var nr = $("#nr").val().substring(0,10); 
<div style="72px;width:202px;" > 
<textarea id="nr" style="height:70px;width:200px;" onkeyup="tjzs()" onpropertychange="if (value.length>10) value=value.substring(0,10)"></textarea> 
 Word limit: <input type="text" id="zs" value="0" lang="4"/>0/10 

Related articles: