jQuery implements the method of counting the number of input words

  • 2020-05-12 02:14:13
  • OfStack

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">
<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>
    <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>
<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>";
  var string = "<span style=\"color:#FF0000\">"+value+"</span>/80";

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

Related articles: