First, the realization effect:
In order to more intuitively reflect the user in the text box input text can see how many words they entered, the project needs to be judged by the text box remaining to enter the number of words.
HTML & JS:
1 <Div>2 <textareaname= "Content"ID= "Content"onkeyup= "Javascript:checkwords (this);"
OnMouseDown= "Javascript:checkwords (this);" ></textarea>3 </Div>4 <Div> 5You can also enter<spanstyle= "Font-family:georgia; font-size:26px;"ID= "Wordcheck">80</span>a kanji6 </Div> 7 8 <Script>9 varMaxstrlen= the;Ten functionQ (s) { One returndocument.getElementById (s); A } - functionCheckwords (c) { - Len=Maxstrlen; the varStr=C.value; - Mylen=Getstrleng (str); - varWck=Q ("Wordcheck"); - if(Mylen>Len*2){ + C.value=str.substring (0, I+1); - }Else{ + wck.innerhtml=Math.floor (Len*2-Mylen)/2); A } at } - functionGetstrleng (str) { - Mylen= 0; - I= 0; - for(;(i<str.length)&&(Mylen<=Maxstrlen*2); I++){ - if(Str.charcodeat (i)>0&&str.charcodeat (i)< -) in Mylen++; - Else to Mylen+=2; + } - returnMylen; the }
The above can be dynamically judged text box can enter the remaining words, data from the network.
JS implementation of dynamic prompt text box to enter the remaining words (similar to the publication of micro-blog digital Tips)