<script>
function check() {
   alert(t.value.length);
}
</script>
<textarea name=t width="30" height="5"></textarea>
<input type="button" value="asfads" onclick="return check()">

解决方案 »

  1.   

    <script>
    function check() {
       alert(t.value.length);
       if(t.value.length>20) {
          alert("大于");
    }
    }
    </script>
    <textarea name=t width="30" height="5"></textarea>
    <input type="button" value="asfads" onclick="return check()">
      

  2.   

    <script>
    function check(src){
    if(src.value.length>20){alert("不要再输入")}
    }
    </script><textarea rows="5" name="S1" cols="20" onkeydown="check(this)"></textarea>
      

  3.   

    function  checkFieldLength(formName,fieldName,fieldDesc,fieldLength )


    var str = eval("document."+formName+"."+fieldName+".value");
    var theLen=0;
      var teststr='';
    for (i=0;i<str.length;i++)
    {
    teststr=str.charAt(i); 
       if(str.charCodeAt(i)>255)
        theLen=theLen + 2;
       else
    theLen=theLen + 1;
    }
    if( theLen>fieldLength )
    {
    alert(fieldDesc+" 的字段长度超过规定长度!");
    eval("document."+formName+"."+fieldName+".focus()");
    return false;
    }
    else
    {
    return true;
    }
    }