日期:2014-05-16 浏览次数:20341 次
<input type="text" id="demo" /><span id="msg"></span> <script type="text/javascript"> var limit = 10; //限制10个字符 document.getElementById('demo').onkeyup = function() { var len = this.value.length, msg = '已输入' + len + '个字符,最多可输入' + limit + '个字符,'; if (len <= limit) msg += '还可以输入' + (limit - len) + '个字符'; else msg += '已超过限制' + (len - limit) + '个字符'; document.getElementById('msg').innerHTML = msg; } </script>