zoukankan      html  css  js  c++  java
  • 苹果手机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”事件不能生效,原因暂时未知,用原生事件没问题。
  • 相关阅读:
    Iscroll4使用心得 (转)
    请求接口数据实例
    jQuery插件开发全解析(转)
    js中可以改变作用域的三种方式(改变this)
    this基础(转)
    Hash扫盲
    JS编码解码 (转)
    自定义菜单实例
    DOM(转)
    js扫盲
  • 原文地址:https://www.cnblogs.com/bulaliu/p/8965600.html
Copyright © 2011-2022 走看看