<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文本框输入还剩多少字数统计代码示例</title>
<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("留言不能超过 100 个字!");
}
else {
used.value = message.value.length;
remain.value = max - used.value;
}
}
</script>
</head>
<body>
<form name="Myform1" method="post">
<table>
<tr class="tdbg_leftall">
<td valign="middle" align="center">留言内容: <br> </td>
<td colspan="4" valign="top"><textarea name="GuestContent" cols="59" rows="6" onkeydown=gbcount(this.form.GuestContent,this.form.total,this.form.used,this.form.remain); onkeyup=gbcount(this.form.GuestContent,this.form.total,this.form.used,this.form.remain);></textarea></td>
</tr>
<tr class="tdbg_leftall">
<td valign="middle" align="center"></td>
<td colspan="4" valign="top">
最多字数:<INPUT disabled maxLength=4 name=total size=3 value=100>
已用字数:<INPUT disabled maxLength=4 name=used size=3 value=0>
剩余字数:<INPUT disabled maxLength=4 name=remain size=3 value=500> </td>
</tr>
</table>
</form>
</body>
</html> |