1 var text = document.getElementById('demo'); 2 var count = document.getElementById('count'); 3 var handle = function(){ 4 var evt = window.event || arguments.callee.caller.arguments[0]; 5 //evt.target 不支持ie10及以下浏览器 || evt.srcElement 不支持火狐浏览器 6 var src = evt.target || evt.srcElement; 7 count.innerText = src.value.length; 8 } 9 if(text.addEventListener){ 10 text.addEventListener('input',handle,false); 11 }else if(text.attachEvent){ 12 text.attachEvent('onpropertychange',handle); 13 }else{ 14 text['onpropertychange'] = handle; 15 }