日期:2014-05-16  浏览次数:20426 次

textarea中限制输入字符个数的问题,顶者有分!
<html>
<head>
</head>
<script   type= "text/javascript ">
function   validate(obj)
{
if(obj.value.length   > =   1000)
{
alert( "you   can   olny   input   less   than   1000   characters! ");
}
}
</script>
<body>
<textarea   id= "xxxid "   name= "xxxname "   rows= "5 "   cols= "60 "       onkeyup= "validate(this); ">
</textarea>
</body>
</html>

就这个页面,有个textarea用来输入文本。输入的文本个数限制在1000个,多了就弹出个提示,就我上面那样。现在还想更进一步,就是到了1000个就不让他写了,我上面那个就是超过了1000个字数还是可以写,不爽,看怎么能不让他再写了,跟文本框一样,超过最大字数后面就没法写了。各位给点意见,顶者有分,谢了!

------解决方案--------------------
<script language= "javascript ">
function textCounter(content) {
if (content.length > 1000) document.zb.Content.value=document.zb.Content.value.substring(0, 1000);
}
</script>

<textarea name= "Content " cols= "50 " rows= "10 " onPropertyChange= "textCounter(form1.content.value) "> </textarea>


<
------解决方案--------------------

<html>
<head>
</head>
<script type= "text/javascript ">
function validate(obj)
{
if(obj.value.length > = 10)
{
alert( "you can olny input less than 1000 characters! ");
event.returnValue=false;
}
}
</script>
<body>
<textarea id= "xxxid " name= "xxxname " rows= "5 " cols= "60 " onkeydown= "validate(this); ">
</textarea>
</body>
</html>
------解决方案--------------------
<html>
<head>
</head>
<script type= "text/javascript ">
function validate(obj)
{
if(obj.value.length > = 10)
{

obj.setAttribute( 'disabled ', 'disabled ');
//alert( "you can olny input less than 1000 characters! ");
}
}
</script>
<body>
<textarea id= "xxxid " name= "xxxname " rows= "5 " cols= "60 " onkeyup= "validate(this); ">
</textarea>
</body>
</html>
------解决方案--------------------
我也来一个
<html>
<head>
</head>
<script type= "text/javascript ">
function validate(obj)
{
if(obj.value.length > = 100)
{

obj.setAttribute( 'disabled ', 'disabled ');
//alert( "you can olny input less than 100 characters! ");
}
}
</script>
<body>
<textarea id= "xxxid " name= "xxxname " rows= "5 " cols= "60 " onkeypress= "validate(this); ">
</textarea>
</body>
</html>

;)
------解决方案--------------------
<html>
<head>
</head>
<script type= "text/javascript ">
/**
*checkMaxLength.