jQuery implements the method of counting the number of input words


The example of this paper describes the method of jQuery to calculate the number of input words. Share with you for your reference. The details are as follows:

jQuery statistics input text number can be used in statistics reply word length, title word length prompt, increase the friendliness to improve the user experience. The code is as follows:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Number of words </title>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<ul>
  <li>
    <span> News headlines :</span>
    <span><input id="news_title" name="news_title" type="text" size="60" onkeyup="title_len();" onclick="title_len();"  maxlength="80"/>
    <span id="titlelen">0/80</span>
  </li>
</ul>
</body>
<script language="javascript" type="text/javascript">
function title_len(){
 var value = $('#news_title').val().length;
 if(value == 80){
  var string = "<span style=\"color:#FF0000\">"+value+"/80</span>";
 }else{
  var string = "<span style=\"color:#FF0000\">"+value+"</span>/80";
 }
 $('#titlelen').html(string);
}
</script>
</html>

I hope this article has been helpful to your jQuery programming.