可以模拟一个,不够好:失去焦点的时候进行判断
<textarea name=show rows=10 cols=80 style="maxlength:10" onblur=check(this)></textarea>
<script>
String.prototype.getLength = function(){
//得到字符串的真实长度
  var l=this.length;
  var n=l
  for (var i=0;i<l;i++){
    if (this.charCodeAt(i)<0||this.charCodeAt(i)>255) n++
  }
  return n
}function check(obj){
var max=obj.style.maxlength;
if(obj.value.getLength()>max) {
alert("最大允许长度是"+max);
obj.focus();
obj.select();
}
}
</script>

解决方案 »

  1.   

    处理一下onkeydown、onpaste可以模拟的更像样一点
      

  2.   

    这个就更象了,比input的maxlength还好一点点:)
    <input maxlength=10><p>
    <textarea name=show rows=10 cols=80 style="maxlength:10" onkeydown='return check(this)' onpaste='return checkPaste(this)'></textarea>
    <script>
    String.prototype.getLength = function(){
    //得到字符串的真实长度
      var l=this.length;
      var n=l
      for (var i=0;i<l;i++){
        if (this.charCodeAt(i)<0||this.charCodeAt(i)>255) n++
      }
      return n
    }function check(obj){
    var nKeyCode=event.keyCode;
    if(nKeyCode==8 || nKeyCode==46) return true;
    var rng=document.selection.createRange();
    var nLeft=obj.style.maxlength-obj.value.getLength()+rng.text.getLength();
    if(nLeft<=0) return false;
    return true;
    }
    function checkPaste(obj){
    var rng=document.selection.createRange();
    var nLeft=obj.style.maxlength-obj.value.getLength()+rng.text.getLength();
    if(nLeft<=0) return false;
    var strCopy=window.clipboardData.getData("Text");
    var i=nLeft;
    while(strCopy.getLength()>nLeft && i>0){
    strCopy=strCopy.substring(0,i--);
    }
    if(strCopy.getLength()>nLeft) return false;
    rng.text=strCopy;
    return false;
    }
    </script>
      

  3.   

    http://tech.enet.com.cn/document/20010219/2001021913151901.shtmltest.html:
    <form method="POST">
    <p><input type="text" size="30" maxlength="50" name="T1">
    <textarea name="S1" rows="4" cols="30" maxlength="50" style="behavior:url(maxlength.htc)"></textarea>
    </form>maxlength.htc:<PUBLIC:COMPONENT id="bhvMaxlength" urn="maf:Maxlength">
    <PUBLIC:PROPERTY name="maxLength" />
    <PUBLIC:ATTACH event="onkeypress" handler="doKeypress" />
    <PUBLIC:ATTACH event="onbeforepaste" handler="doBeforePaste" />
    <PUBLIC:ATTACH event="onpaste" handler="doPaste" /><SCRIPT language="JScript">
    // Keep user from entering more than maxLength characters
    function doKeypress(){
    if(!isNaN(maxLength)){
    maxLength = parseInt(maxLength);
    var oTR = element.document.selection.createRange();
    // Allow user to type character if at least one character is selected
    if(oTR.text.length >= 1)
    event.returnValue = true;
    else if(value.length > maxLength-1)
    event.returnValue = false;
    }
    }
    // Cancel default behavior
    function doBeforePaste(){
    if(!isNaN(maxLength))
    event.returnValue = false;
    }
    // Cancel default behavior and create a new paste routine
    function doPaste(){
    if(!isNaN(maxLength)){
    event.returnValue = false;
    maxLength = parseInt(maxLength);
    var oTR = element.document.selection.createRange();
    var iInsertLength = maxLength - value.length + oTR.text.length;
    var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
    oTR.text = sData;
    }
    }
    </SCRIPT></PUBLIC:COMPONENT>
      

  4.   

    X!秋水已经贴了,这是小狗写的那个htc吧。看到这个问题我还准备特意去理解一下这个htc,然后再贴上来的-_-
      

  5.   

    原来是豆腐写的,my mistake!
      

  6.   

    HTC果然很精妙,但是发现doKeypress大有问题:输入中文的时候就超过了允许的最大长度;我的写法,如果最后只剩下一个字符长度,然后输入一个中文的话也是可以的,这样实际长度就变成11>10了
      

  7.   

    htc文件有什么用阿?
    怎么运行?