怎样控制文本区字数的个数

来源:百度知道 编辑:UC知道 时间:2024/04/19 09:08:55
如果文本区(<textarea></textarea>)输入的字数少于10个字,就弹出对话提示要输入多于10个文字.

只能在这个表单提交的时候调用一个脚本去检测。或在后台脚本中检测也可以。
<form name=form1 action=post onSubmit='return check();'>
<textarea name=xx></textarea>
<input type=submit value='提交'>
</form>
前台脚本:
<script>
function check(){
if(form1.xx.length<=10){
alert('少于10个字!');
return false;
}
return true;
}
</script>
后台脚本:
dim xx
xx=request("xx")
if len(xx)<=10 then
response.write "<script>alert('少于10字!');history.go(-1);</script>"
response.end
end if

//文本区字数限制实现
function getLength(){
var txtVal=document.getElementById("xx.xxx").value;
var count=txtVal.length;
if(count>=3999) {
document.getElementById("xx.xxx").value = document.getElementById("xx.xxx").value.substring(1,4001);
}
$("#txtMsg").text(count);