Specifying maxlength for multiline textbox

后端 未结 19 2045
感动是毒
感动是毒 2020-11-27 15:21

I\'m trying to use asp:


I want a way to spe

19条回答
  •  余生分开走
    2020-11-27 16:09

    try this javascript:

    function checkTextAreaMaxLength(textBox,e, length)
    {
    
            var mLen = textBox["MaxLength"];
            if(null==mLen)
                mLen=length;
    
            var maxLength = parseInt(mLen);
            if(!checkSpecialKeys(e))
            {
             if(textBox.value.length > maxLength-1)
             {
                if(window.event)//IE
                  e.returnValue = false;
                else//Firefox
                    e.preventDefault();
             }
        }   
    }
    function checkSpecialKeys(e)
    {
        if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
            return false;
        else
            return true;
    }
    

    On the control invoke it like this:

     
    

    You could also just use the checkSpecialKeys function to validate the input on your javascript implementation.

提交回复
热议问题