js
function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else countfield.value = maxlimit - field.value.length; }
html
<form name=myform action=""> <textarea name="message" cols="28" rows="5" onKeyDown="textCounter(message,remLen,1000);" onKeyUp="textCounter(message,remLen,1000);"></textarea> 您还可以输入:<input name="remLen" type="text" value="1000" size="5" readonly="readonly">个字符 </form>