实时统计输入的文字

<body>

  <input type="input"/><span></span>

  <script>

    var  oT=document.querySelector('input');

    var oS=document.querySelector('span');

    if(window.navigator.userAgent.toLowerCase().indexOf('msie 9.0') !=-1){

      var timer=null;

      oT.onfocus=function(){

        timer=setInterval(function(){

          oS.innerHTML=oT.value.length;

        })

      }

      oT.onblur=function(){

        clearInterval(timer);

      }

    }else{

      oT.oninput=oT.propertychange=function(){

        oS.innerHTML=oT.value.length

      };

    }

  </script>

</body>

posted @ 2017-04-13 13:53  少华ShaoHua  阅读(161)  评论(0编辑  收藏  举报