简体   繁体   中英

Jquery bug in Android Chrome

I have the below jquery which is working fine on desktop browsers, when I load it on an android mobile chrome and when I start typing, the second letter goes before the first letter and others follows the second letter.

Here is an image how its working...

Can anyone help me solve this out please?

 $("#textbox").on('input', function(evt) {
          if(this.lengh == 0) return $(this);

          var input = $(this);
          var start = input[0].selectionStart;
          $(this).val($(this).val().replace(/[^a-zA-Z0-9 +:%=\\/-]/gi,""))
          $(this).val(function (_, val) {
            return val.toUpperCase();
          });
          input[0].selectionStart = input[0].selectionEnd = start;
        });

The problem is when, in Android, the selectionStart is zero.

Test it with your phone: http://www.vixed.it/st/34947263/

$("#textbox").on('input', function(e) {
    e.preventDefault();
    var input = $(this);
    var start = input[0].selectionStart;
    var inputTextChanged = input.val().replace(/[^a-zA-Z0-9 +:%=\\/-]/gi,"").toUpperCase();
    input.val(inputTextChanged);
    if (start>=1) input[0].selectionEnd = start;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM