search

Home  >  Q&A  >  body text

javascript - input cursor position is misplaced

In the input input box on the mobile phone, use the following code to set the format of the mobile phone number to "000 0000 0000", and add a space in the middle of the mobile phone number.

if (mValue != '') {
      let mLength = mValue.length;
      if (mLength <= 3) {
        return mValue;
      } else {
        if (mLength <= 7) {
          return mValue.substring(0, 3) + ' ' + mValue.substring(3, mLength)
        } else {
          return mValue.substring(0, 3) + ' ' + mValue.substring(3, 7) + ' ' + mValue.substring(7, 11)
        }
      }
    }

Personal test is normal, but it will appear on Huawei mate9. Every time when entering the third number, when adding a space, it will be displayed that the space has been added normally, but the cursor is in front of the space and the number is entered again. The cursor is always in front of the last number.

我想大声告诉你我想大声告诉你2750 days ago719

reply all(1)I'll reply

  • 黄舟

    黄舟2017-05-18 11:03:58

    I also encountered this problem, have you solved it and how did you solve it

    reply
    0
  • Cancelreply