The popular Weibo websites such as Twitter have a good user experience. When entering text in the text box, the characters entered will be automatically counted and the characters that users can still enter will be displayed. In Weibo blogs with a limit of 140 characters, such a small tip can greatly enhance the user experience.
If I implement this technology, I have conducted 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 statistics on text are exactly the same as those of Weibo blogs such as Twitter.
The usage method is to first add a span to display the remaining word count, then add an onkeydown and onkeyup events in Textarea, and call another JavaScript function. The parameters of the function call are the span id and the textarea id, and then use innerHTML in JavaScript to return the calculated remaining word count.
Core Javascript code:
<span style="font-size:18px;"><script language="javascript">
function countChar(textareaName,spanName)
{
(spanName).innerHTML = 140 - (textareaName).;
}
</script>
You can enter <span >140</span> words<br/>
<textarea name="status" rows="6" cols="40" onkeydown='countChar("status","counter");'
onkeyup='countChar("status","counter");'></textarea></span>
PS: This site also provides an online tool for word counting. Interested friends can refer to it:
Online word count tool:
http://tools./code/zishutongji