Home > Web Front-end > JS Tutorial > JavaScript compatible text input length prompt for Firefox_Form special effects

JavaScript compatible text input length prompt for Firefox_Form special effects

WBOY
Release: 2016-05-16 19:03:59
Original
1115 people have browsed it

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> function checkLen() {var obj=inputTxt var maxLen=parseInt(obj.getAttribute('maxlength')) //最大限制输入的字符数量 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.slice(0,(z + 1)); break; } } } if(llen<0)llen=0 if(len<maxLen)len=maxLen document.getElementById('msg').innerHTML='已输入字符数量:'+len+' 剩余数量:'+llen } var inputTxt=document.getElementById('txt'); if(!/msie/i.test(navigator.userAgent)) inputTxt.addEventListener("input",checkLen,false); else {inputTxt.onpropertychange=checkLen} </script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template