• IOS中div contenteditable=true无法输入 fastclick.js在点击一个可输入的div时,ios无法正常唤起输入法键盘


    原文地址: https://blog.csdn.net/u010377383/article/details/79838562

    前言
    为了提升移动端click的响应速度,使用了fastclick.js这么一个库。

    这个库导致这个可编辑的div被点击无法轻松的唤起输入法。
    长按才能成功。div的一个contentEditable=”true”

    解决方案
    首先:再你的编辑器中增加一个class属性。我用的是quilljs

    
    <div id="editor" class="needsclick"></div>
    
    然后我们去main.js(我是基于vue在做)重写他原型上的needsClick方法(源码在229行)
    
    其实你也可以选择fark插件修改,放在本地库
    
    import FastClick from 'fastclick'
    // const $ = window.$
    // 点击延迟 因为和编辑器冲突, 重制起原型方法needsClick
    const deviceIsWindowsPhone = navigator.userAgent.indexOf('Windows Phone') >= 0
    const deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone
    FastClick.prototype.needsClick = function (target) {
      // 下面这句
      // 这是jq写法
      // if ($(target).parents('.needsclick').length) return true
      while (target.tagName !== 'BODY') {
       // 放在本地插件库, 请将includes换成indexOf判断
        if (target.className.includes('needsclick')) return true
        target = target.parentNode
      }
    
      switch (target.nodeName.toLowerCase()) {
        // Don't send a synthetic click to disabled inputs (issue #62)
        case 'button':
        case 'select':
        case 'textarea':
          if (target.disabled) {
            return true
          }
    
          break
        case 'input':
    
          // File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
          if ((deviceIsIOS && target.type === 'file') || target.disabled) {
            return true
          }
    
          break
        case 'label':
        case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
        case 'video':
          return true
      }
    
      return (/needsclick/).test(target.className)
    }
    FastClick.attach(document.body)
    
  • 相关阅读:
    java内部类自我总结
    eclipse中调试第三方jar中的代码
    java提升性能的好习惯(转)
    WMI获取驱动版本
    cmd中的特殊符号
    DISM命令应用大全
    C#自检系统
    注册表检查
    PictrueBox 显示Resources里面的图片
    Linq to XML
  • 原文地址:https://www.cnblogs.com/taoquns/p/9662262.html
Copyright © 2020-2023  润新知