码迷,mamicode.com
首页 > 移动开发 > 详细

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

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

标签:was   sof   cti   span   有用   mount   style   mic   ever   


原因:

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没有效果 键盘跳不出来

标签:was   sof   cti   span   有用   mount   style   mic   ever   

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

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!