【Html代碼】
<table> <tr> <td width="150">短信內容:</td> <td> <textarea name="message" cols="96" rows="5" onKeyDown="textCounter(message,remLen,65);" onKeyUp="textCounter(message,remLen,65);"></textarea> <td> </tr> <tr><td></td> <td>您還可以輸入:<input name="remLen" type="text" value="65" size="5" readonly="readonly">個字符,每條短信最大允許輸入<strong>65</strong>個字符</td> </tr> </table>
【對應的js代碼】
<script> function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else countfield.value = maxlimit - field.value.length; } </script>