the input ios focus (), autofocus processing is invalid

Focus appears invalid reasons:

ios of UIWebView default KeyboardDisplayRequiresUserAction is false, set to true on the line, WKWebView does not support this property, if you want to start a native resolved, please refer https://stackoverflow.com/questions/32407185/wkwebview-cant-open-keyboard-for -input-field

Solutions:

As can be seen from invalid reason, the keyboard requires the user to trigger pop-up, which led to the autofocus or element.focus () is not valid, therefore, go to the pop-up keyboard focus in the case, or jump to the page with the autofocus will can properly focus the

Solution:

The usual scenario is that we click on a page element => Logic interaction => want to focus elements, or jump to have aotufocus page. Here again there is a premise is to have the page, click behavior.

Plan focuses

As long as the callback click event on the ability to focus to input, so either click again to generate input focus to this input, or jump to the autofocus of the page, click the focus to the first use of a placeholder input from the keyboard tone, in the presence of the keyboard in the case of calls element.focus () or jump to the page you have autofocus can be a normal focus.

.clip{
  position: absolute;
  clip: rect(0 0 0 0);
}

<input ref="tempFocus" class="clip">

<div @click="gotoCommentClick">快来留言吧!</div>

gotoCommentClick() {
  this.afterLogin().then(_ => {
    this.$refs.tempFocus.focus();
    this.$router.push(this.$route.path + '/comment');
  })
},
mounted() {
    this.$refs.editor.focus();
  }

Caution is transferred from the keyboard if the recovery will still focus (), autofocus invalid;

Reference article input on ios focus (), autofocus ineffective treatment methods

Published 58 original articles · won praise 20 · views 110 000 +

Guess you like

Origin blog.csdn.net/fly_wugui/article/details/89638824