Jelly Bean WebView not working well with HTML maxlength attribute for text box

后端 未结 6 1612
我在风中等你
我在风中等你 2020-12-16 00:37

Jelly Bean doesn\'t seem to like the maxlength attribute of HTML for text input. It certainly restricts the number of input characters but the moment you attemp

6条回答
  •  半阙折子戏
    2020-12-16 01:02

    Handle the keypress separately for input fields where you need to restrict the maxlength by adding a separate class and listen keypress for that class.

    HTML

    
    

    Javascript

    $(".charlength").keypress(function(event) {
              if(event.which >= 32 || event.which == 13) {
              var maxLength = event.currentTarget.maxLength;
               var length = event.currentTarget.value.length;
               if(length >= maxLength) {                     
                   event.preventDefault();
               }
           }
       });
    

提交回复
热议问题