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

JS如何判断textarea的内容长度
JS如何判断textarea的内容长度,我用if   (document.add.a59.value.length <100){alert( "不能少于100字! ");add.a59.focus();return;}不能实现   多谢指点


------解决方案--------------------
你的这些写在了哪里?
试试
if (document.add.a59.value.length <100){alert( "不能少于100字! ");add.a59.focus();return false;}


------解决方案--------------------
<html>

<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> New Page 2 </title>
</head>

<body>
<textarea > </textarea> <input type=button value=check onclick= "checkMaxLength(this.previousSibling,20) "
</body>

</html>
<script>
/**
*checkMaxLength.
*JK 2006-11-26
*/
function checkMaxLength(textareaObj,maxLength)
{
if(maxLength == null) maxLength=textareaObj.getAttribute( "maxLength ");
if(maxLength == null) maxLength=1024;
var currentLength = textareaObj.value.length;
if (currentLength > maxLength) {
alert( "The length of your input ( "+currentLength+ ") is larger than the maxLength ( "+maxLength+ ") . ");
if(textareaObj.createTextRange){
var textRange=textareaObj.createTextRange();
textRange.moveStart( 'character ',10);
textRange.select();
}
else textareaObj.select();
textareaObj.focus();
return false;
}
return true;
}


</script>