This article mainly introduces theJavaScriptimplementation of the instant check function of imitating the original input word count of Sina Weibo, involvingjavascript eventresponse andstring traversal, conversion, judgment and other related operation skills, friends who are familiar with JavaScript can refer to this article
It is not difficult to check the number of words entered while entering characters in the text box. However, due to the way some of the functions are used, it is easy for people to get confused. It is easy to mess around with the entire result without getting it, and it is also easy for bugs to occur. Note that the length function can no longer be used here, because this thing counts as one character in English and Chinese characters. Counts as one character and does not conform to the form of data transmission. The OnChange event cannot be used anymore. This event will only be triggered when the cursor leaves the text box. It must be changed to the more immediate OnKeyUp.
1. Basic goal
#As shown below, complete an imitation of Sina Weibo without any plug-ins, pure Javascript without JQuery with word count Statistics input box, if the word count is exceeded, corresponding prompts will be given.
English counts as half a word, Chinese only counts as 1 character.
2. Basic layout
There is nothing to say. The main prompt text is to give an ID=test. Because the word count changes from time to time, an ID=wordLength must also be given. Then the inputTest function at the script triggers the onkeyup event of the text box and passes its current value at the same time. past. At the same time, I noticed that the reason why the word count section is similar to that on Sina Weibo is because Sina Weibo uses the Georgia font, which displays unique numbers.
3. Core script
The above is all the content of this article. I hope it will be helpful to everyone learning JavaScript! !
Related recommendations:
Javascript converts the absolute path of the image into base64 encoding
JavaScript implements mouse wheel control page image switching function example
javascript implements progress bar function example based on timer
The above is the detailed content of Real-time check function of input word count imitating Sina Weibo's original ecology implemented by JavaScript. For more information, please follow other related articles on the PHP Chinese website!