数字统计 边输入边统计
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title> </title> </head> <body> <span id="span"></span> <textarea name="#" id="show" cols="30" rows="10"></textarea> <script type="text/javascript"> var oSpan=document.getElementById('span'); var oShow=document.getElementById('show'); var timer=null; // oShow.oninput=function(){ // firfox 和chrome 兼容 ie8不兼容 // oSpan.innerHTML=this.value.length; // } // oShow.onpropertychange=function(){ // //此事件只有ie兼容 ie10 以下 // oSpan.innerHTML=this.value.length // } //以下这种写法 ie 火狐 chrome都兼容 oShow.onfocus=function(){ clearInterval(timer); timer=setInterval(function(){ oSpan.innerHTML=oShow.value.length; },5000) } oShow.onblur=function(){ clearInterval } </script> </body> </html>