Home  >  Article  >  Web Front-end  >  jQuery operates input box to count word count

jQuery operates input box to count word count

php中世界最好的语言
php中世界最好的语言Original
2018-04-19 15:59:221907browse

This time I will bring you jQueryOperation input box to count the number of words, jQuery operation input box to count the number of wordsWhat are the precautions, the following is a practical case, let's come together take a look.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="jquery-1.7.2.min.js"></script>
</head>
<body>
<p class="container">
  <input id="abc"value=""><span id="WordCountShow"></span>
</p>
<script>
  $.fn.extend({
    wordCount:function(maxLength, wordWrapper) {
      varself =this;
      $(self).attr("maxlength", maxLength);
      showWordCount();
      $(this).on("input propertychange", showWordCount);
      functionshowWordCount() {
        curLength = $(self).val().length;
        varleaveCount = maxLength - curLength;
        wordWrapper.text(leaveCount +"/"+ maxLength);
      }
    }
  })
  $(function() {
    $("#abc").wordCount(10, $("#wordCountShow"));
  })
</script>
</body>
</html>

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Recommended reading:

jQuery cookie to achieve skin-changing effect

jQuery to create page mask layer effect

The above is the detailed content of jQuery operates input box to count word count. For more information, please follow other related articles on the PHP Chinese website!

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