你的位置: Kiyo'Space首页 HTML/CSS/特效 阅读文章 欢迎留下您的足迹

在文本框中控制别人输入字数

[ HTML/CSS/特效 ] 分享

脚本说明:
第一步:把如下代码加入<head>区域中
<SCRIPT LANGUAGE="JavaScript">
<!– Begin
maxLen = 130; // max number of characters allowed

function checkMaxInput(form) {
if (form.message.value.length > maxLen) // if too long…. trim it!
form.message.value = form.message.value.substring(0, maxLen);
// otherwise, update ‘characters left’ counter
else form.remLen.value = maxLen – form.message.value.length;
}
// End –>
</script>

第二步:把如下代码加入<body>区域中
<form name=myform action="YOUR-SCRIPT.CGI">
<font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="checkMaxInput(this.form)" onKeyUp="checkMaxInput(this.form)"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="130"> characters left</font>
</form>

没有评论

  • (Required)
  • (Required, will not be published)