Javascript compatible with firefox text input length tip _ form special effects

Source: Internet
Author: User
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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.