TextBox设置多行后,限制输入字数

<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Rows="10" onkeydown="DoKeyPress(500)" onPaste="CheckPaste(500)">



        <script type="text/javascript">
            function DoKeyPress(maxLen){
              var str=event.srcElement.value;
              var oSR=document.selection.createRange();
              if(str.length<maxLen){
                event.returnValue = true;
              }else if(oSR.text.length>0){
                event.returnValue = true;
              }else{
                event.returnValue = false;
              }
            }


             function CheckPaste(maxLen){
              var str=event.srcElement.value;
              var oSR=document.selection.createRange();
              var strData=clipboardData.getData('text');
              var iLenPaste=maxLen-str.length+oSR.text.length;
              oSR.text=strData.substring(0,iLenPaste);
              event.returnValue = false;
            }
        </script>             

你可能感兴趣的:(text)