苹果手机focus没有效果 键盘跳不出来


原因:

In iOS, Safari is now apparently remembering that the element was focussed but not actually focussing it until a touch down event.
It is then blindly sending a click event to whichever element received the touch up.
在IOS中只有用户主动触发的事件才能使focus生效,所以可以在focus之前的用户触发的事件中用focus()方法

比如VUE中 HTML:
<p id="click-ele">点击评论</p>
<input id="input" v-show="isInputShow" type="text"></input>

js如下:
document.getElementByID('click-ele').addEventListener('click',function(){
  vue.isInputShow = true
  document.getElementById('input').focus()

},false)

这样点击评论后,input标签可以focus,键盘也会跳出来。

注意有两点:
(1)document.getElement要在mounted 即DOM结构渲染好之后用,不然获取不到元素。
(2)P标签上直接使用VUE中的@click=“handlerClick”事件不能生效,原因暂时未知,用原生事件没问题。
原文地址:https://www.cnblogs.com/bulaliu/p/8965600.html