The process of writing a page using the TextArea text field, suddenly remembered that he can also add the remaining word count of this function.
The first way of thinking:
Press down on the keyboard key to trigger a method count:
<textarea cols= "rows=" "maxlength=" "title=" can only enter 100 words "ng-model=" text "ng-change=" Tolcount () "></ Textarea>
<p> can also enter {{count}} characters </p>
:
Note: This is not necessary to use JS, said can be counted, but there is a great disadvantage, as long as the keyboard press, on the count, for example, you press the Delete button, he also counted; and if you are copying and pasting on textarea, there is no count.
The second idea: Calculate the remaining number of words according to the length of the input content:
HTML section:
<! DOCTYPE html>
<title> text field word limit </title>
<body ng-controller= "Testctrl" >
<textarea cols= "rows=" "maxlength=" "title=" can only enter 100 words "ng-model=" text "ng-change=" Tolcount () "></ Textarea>
<p> can also enter {{count}} characters </p>
</body>
<script type= "Text/javascript" src= "Jquery.js" ></script>
<script type= "Text/javascript" src= "Angular.min.js" ></script>
<script type= "Text/javascript" src= "Test.js" ></script>
JS section:
var app = Angular.module (' app ', []);
App.controller (' Testctrl ', function ($scope) {
$scope. Count = 100;
$scope. Tolcount = function () {
Console.log ($scope. text.length);
$scope. Count = 100-$scope. text.length;
};
});
:
Angularjs TEXTAREA remaining word count