The following code is compatible with firefox text input length prompts. The length of the input characters is displayed in real time. When the input length is exceeded, it is automatically truncated. To limit the length of text input, maxlength is the upper limit of the text length.
<P id = 'msg '> </p> <textarea maxlength = "10" id = "txt"> </textarea> script function checkLen () {var obj = inputTxt var maxLen = parseInt (obj. getAttribute ('maxlength') // maximum number of characters to be entered var len = obj. value. replace (/[^ \ x00-\ xff]/g, 'oo '). length; var llen = maxLen-len; if (len> maxLen) {var I = 0; for (var z = 0; z <len; z ++) {if (obj. value. charCodeAt (z)> 255) {I = I + 2;} else {I = I + 1;} if (I >= maxLen) {obj. value = obj. value. slic E (0, (z + 1); break ;}}if (llen <0) llen = 0 if (len <maxLen) len = maxLen document. getElementById ('msg '). innerHTML = 'number of entered characters: '+ len +' remaining quantity: '+ llen} var inputTxt = document. getElementById ('txt '); if (! /Msie/I. test (navigator. userAgent) inputTxt. addEventListener ("input", checkLen, false); else {inputTxt. onpropertychange = checkLen} script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]