代码如下:<form action="" method=post name=form> <script language=javascript> function gbcount(message,total,used,remain) { var max; max=total.value; if(message.value.length > max){ message.value = message.value.substring(0,max); used.value = max; remain.value = 0; alert('留言不能超过50个字!'); } else{ used.value = message.value.length; remain.value = max - used.value; } } </script> <body> <textarea name='GuestContent' cols='60' rows='6' οnkeydοwn=gbcount(this.form.GuestContent,this.form.total,this.form.used,this.form.remain); οnkeyup=gbcount(this.form.GuestContent,this.form.total,this.form.used,this.form.remain);></textarea> <br> 最多字数:<INPUT disabled maxLength=4 name=total size=3 value=50> 已用字数:<INPUT disabled maxLength=4 name=used size=3 value=0> 剩余字数:<INPUT disabled maxLength=4 name=remain size=3 value=50> </form> [Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码] 代码如下:<script language="JavaScript"> <!-- Begin function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0,maxlimit); else countfield.value = maxlimit - field.value.length; } // End --> </script> <form method="POST" action="../0001/success.asp" name=form > <textarea cols="45" name="memo" rows="8" wrap="on" class="editbox2" onKeyDown="textCounter(this.form.memo,this.form.remLen,160);" onKeyUp="textCounter(this.form.memo,this.form.remLen,160);"></textarea> <br> 共可输入160字,还剩 <input readonly type=text name=remLen size=3 maxlength=3 value="160" class=editbox1> 字。 <br> <input type=submit value=" 发送 " class=bottom name="submit"> <input type=reset value=" 重填 " class=bottom name="reset"> </form> [Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]