`
txf2004
  • 浏览: 6854198 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

关于textarea超过一定字数,不能提交问题

阅读更多
<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-4490194096475053&amp;dt=1228540492250&amp;lmt=1228528450&amp;prev_slotnames=1891601125&amp;output=html&amp;slotname=3685991503&amp;correlator=1228540491796&amp;url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F10%2F1821.html&amp;ea=0&amp;ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__98.html&amp;frm=0&amp;ga_vid=1085125342.1228540492&amp;ga_sid=1228540492&amp;ga_hid=2000129389&amp;flash=9.0.124.0&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_java=true&amp;dtd=15" frameborder="0" width="300" scrolling="no" height="250" allowtransparency></iframe>
1,<form action="a.jsp">
<textarea rows="20" name="111"></textarea>
<input type="submit" name="ok" value="ok" />
</form>

2,<form action="a.jsp" method="post">
<textarea rows="20" name="111"></textarea>
<input type="submit" name="ok" value="ok" />
</form>

然后你从网上复制一段文章下来,粘贴上去。发现如果textarea长度大于一定值的时候,
1不能提交,2能提交。
呵呵,原来1默认是get方式提交,get提交有字数限制,这就是为什么:一个表单中有textarea框,一旦内容超过几百字符后,点击提交页面无反应。少于这个数量即可正常提交。

脚本判断长度:
<script type="text/javascript">
function CheckTextarea() {
var regC = /[^ -~]+/g;
var regE = /\D+/g;
var str = document.forms[0].tsnr.value;

if (document.forms[0].tsnr.value.length>250){
alert("不能超过250个字符!");
document.forms[0].tsnr.focus();
return (false);
}

// 超过长度 , 截取提交 regC ;中文 regE: 字码
// if (regC.test(str)){
// document.forms[0].tsnr.value = document.forms[0].tsnr.value.substr(0,250);
// }

// if(regE.test(str)){
// document.forms[0].tsnr.value = document.forms[0].tsnr.value.substr(0,500);
// }
}
</script>

<body>

<form action="a.jsp" method="post" onsubmit="return CheckTextarea();">
<textarea rows="20" name="tsnr"></textarea>
<input type="submit" name="ok" value="ok" />
</form>

</body>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics