Home  >  Article  >  Web Front-end  >  JavaScript implements statistical text box Textarea word count to enhance user experience_javascript skills

JavaScript implements statistical text box Textarea word count to enhance user experience_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:45:57929browse

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:

Copy code The code is as follows:


You can enter 140words< br/>

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