Now popular Twitter and other micro-blogging sites, there is a good user experience, that is, in the text box input text, will automatically statistical input characters, and display the user can also enter the characters, in the limited 140 words in the micro-blog, such a small hint can be very good to enhance the user experience.
If this technology is implemented, I did some research, found that the implementation is actually quite simple, a few lines of code can complete the input character statistics, after the actual test, the statistics of the text and Twitter and other micro-blogs are the same.
The way to do this is to add a span to display the remaining words, and then in textarea, add a onkeydown and onkeyup event, call another JavaScript function, and the function call parameter is the span ID and the textarea ID. Then use innerHTML in JavaScript to return the calculated remaining words.
the following are the relevant JavaScript codes:
The following are the referenced contents:
Copy Code code as follows:
<script language= "javascript" >
function Countchar (textareaname , Spanname)
{
document.getElementById (spanname). InnerHTML = 140-document.getelementbyid (textareaname). Value . length;
}
</script>
can enter <span id= "counter" >140</span> word <br/>
<textarea id= "status "Name=" status "rows=" 6 "cols=" Onkeydown= ' Countchar ("status", "Counter"); ' onkeyup= ' Countchar ("status", "Counter" );' ></textarea>