One of the most recent problems in doing a project to the text box in the user input text to be recorded, shown below, because we do is a text messaging platform, now our country's SMS service, if your message exceeds 70 characters, SMS will press two to you issued. So ask us to show the user how many words he entered. So that users know that my message will be divided into several.
In the net a code, put up, start to use, also OK, good, but after using a period of time found the problem. Is that you delete text, the number of words above changes there is a problem, and then studied a bit, to find out where the problem lies. Onkeydown= "Showlen (This)" onkeyup= "Showlen (this) has been used only one method at a time, and no one has used it, these two methods are counted when you press the keyboard and release the keyboard, okay, I'll put the program up.
1 2 3 4 5 6 7 8 9 |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <title > New Document </TITLE> <meta name= "generator" content= "EditPlus" > <meta name= "Author" Content= "" > <meta name= "Keywords" content= "" > <meta name= "Description" content= "" > <mce:script language= "javascript" ><!-- function Showlen (obj) { document.getElementById (" Contentlen ") .value=obj.value.length; document.getElementById (" Smsnum "). Value=math.floor (obj.value.length/ +1; } //--></mce:script> </HEAD> <BODY> < TextArea name= "content" cols= "rows=" "5" id= "Content" onkeydown= "Showlen (This)" onkeyup= "Showlen (This)" > |