首页 > 移动平台 > 详细

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

时间:2018-04-28 10:02:39      阅读:247      评论:0      收藏:0      [点我收藏+]

原因:

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”事件不能生效,原因暂时未知,用原生事件没问题。

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

原文:https://www.cnblogs.com/bulaliu/p/8965600.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!