【Html代码】
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
< 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代码】
1
2
3
4
5
6
7
8
|
<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> |