Features/features:
1. display the number of words that can be entered in real time (in bytes)
2. Two restrictions (length and number of bytes)
3. The Chinese input method can be used normally without any bugs.
4. The same page can be used multiple times without interfering with each other
Limit. js
Function Limit () {<br/> var txtnote; // text box <br/> var txtlimit; // input indicating the number of words <br/> var limitcount; // limit the number of words <br/> var isbyte; // whether to use the byte length limit (1 Chinese Character = 2 characters) <br/> var txtlength; // when the limit is reached, string Length <br/> var txtbyte; <br/> This. init = function () {<br/> txtnote=this.txt note; <br/> txtlimit#this.txt limit; <br/> limitcount = This. limitcount; <br/> isbyte = This. isbyte; <br/> txtnote. onkeydown = function () {wordslimit ()}; txtnote. onkeyup = function () {wordslimit () }; <br/> txtlimit. value = limitcount; <br/>}< br/> function wordslimit () {<br/> var notecount = 0; <br/> If (isbyte) {notecount = txtnote. value. replace (/[^/x00-/xFF]/g, "XX "). length} else {notecount = txtnote. value. length} <br/> If (notecount> limitcount) {<br/> If (isbyte) {<br/> txtnote. value = txtnote. value. substring (0, txtlength + math. floor (limitcount-txtbyte)/2); <br/> txtbyte = txtnote. value. replace (/[^/x00-/xFF]/g, "XX "). length; <br/> txtlimit. value = limitcount-txtbyte; <br/>}else {<br/> txtnote. value = txtnote. value. substring (0, limitcount); <br/> txtlimit. value = 0; <br/>}< br/>} else {<br/> txtlimit. value = limitcount-notecount; <br/>}< br/> txtlength = txtnote. value. length; // record the length after each input <br/> txtbyte = txtnote. value. replace (/[^/x00-/xFF]/g, "XX "). length; <br/>}< br/>}
Page call:
<HTML> <br/> <body> <br/> <input id = "txtnote"/> <br/> You can also enter <input type = "text" id =" txtcount "/> characters <br/> </body> <br/> <MCE: script Type = "text/JavaScript"> <! -- <Br/> var Lim = new limit (); <br/> lim.txt note = document. getelementbyid ("txtnote"); <br/> lim.txt Limit = document. getelementbyid ("txtcount"); <br/> Lim. limitcount = 20; <br/> Lim. isbyte = true; <br/> Lim. init (); <br/> // --> </MCE: SCRIPT> <br/> </ptml>