html:text中有maxlength属性 字段长度超过maxlength时 键盘输入无效
在html:textarea中如何实现这样的功能 即超过一定长度时 键盘输入无效!
请高手帮忙

解决方案 »

  1.   

    比如输入长度不超过200
    <textarea rows="5" cols="50" onKeyUp="if(this.value.length > 200){this.value=this.value.substr(0,200);}"></textarea>
      

  2.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function key_down(obj,e){
    if(window.event) e = window.event;
    if(obj.value.length>=200){
    e.keyCode=0;
    e.returnValue=false; 
    }
    }
    </script>
    </head><body>
    <textarea rows="5" cols="50" onkeydown="key_down(this,event)"></textarea>
    </body></html>
      

  3.   

    IE里可用
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    function pro_change(obj){
    if(obj.value.length>200){
    obj.value = obj.value.substr(0,200);
    }
    }
    </script>
    </head><body>
    <textarea rows="5" cols="50" onpropertychange="pro_change(this)"></textarea>
    </body></html>