简体   繁体   中英

Javascript not working on mobile but works on desktop for tab to next field for four otp box

let element = $event.srcElement.nextElementSibling;
element.focus()

Here next element sibling is not working.

if enter 1st number into box 1 then it tab to next box automatically, it working fine in desktop browser but not in mobile browser?

<input type="text" #otpvalue1 maxlength="1" [value]="otpValue1" (paste)="pasteEvent($event)" (keypress)="otpBox1($event)" (keydown)="handleBackSpaceBox1($event)"/>
                        <input type="text" #otpvalue2 maxlength="1" [value]="otpValue2" (paste)="pasteEvent($event)"  (keypress)="otpBox2($event)" (keydown)="handleBackSpaceBox2($event)">
                        <input type="text" #otpvalue3 maxlength="1" [value]="otpValue3" (paste)="pasteEvent($event)"  (keypress)="otpBox3($event)" (keydown)="handleBackSpaceBox3($event)">
                        <input type="text" #otpvalue4 maxlength="1" [value]="otpValue4" (paste)="pasteEvent($event)"  (keypress)="otpBox4($event)" (keydown)="handleBackSpaceBox4($event)" />

otpBox1(obj) {
    obj = (obj) ? obj : window.event;
    let charCode = (obj.which) ? obj.which : obj.keyCode;
    if ((charCode > 31 || charCode == 13) && (charCode < 48 || charCode > 57)) {
      return false;
    }
    else {
      this.otpValue1 = obj.key;
      let otplength = this.otpValue1 + this.otpValue2 + this.otpValue3 + this.otpValue4;
      this.otplength = otplength.length;
      let element = obj.srcElement.nextElementSibling;
      if (element != null) {
        element.focus();
        obj.preventDefault();
      }
      return true;
    }
  }


more code needed.. how are you deciding wether or not to jump ahead? many events are very different between touch devices and those controlled by a plugged in keyboard and mouse!

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