Nowadays, popular microblogging websites such as Twitter have a good user experience. When entering text in the text box, the entered characters will be automatically counted and the characters that the user can still enter will be displayed. This is limited to 140 characters. In microblogs, small tips like this can greatly enhance the user experience.
What if this technology is implemented? I did some research and found that the implementation is actually quite simple. A few lines of code can complete the input character statistics function. After actual testing, its text statistics are consistent with microblogs such as Twitter. are exactly the same.
The method of use is to first add a span to display the remaining number of words, then add an onkeydown and onkeyup event in the Textarea, and call another JavaScript function. The parameters of the function call are the id and span of the span. The id of the textarea, and then use innerHTML in JavaScript to return the calculated remaining word count.
The following is the relevant JavaScript code:
The following is the quoted content: