1

**在做表单时,在pc浏览器中测试正常,在ios移动端测试出现问题。轻击input无法唤起软键盘,无法对输入框聚焦,必须长按或重压才可以。
经过测试,发现是由于引入fastclick.js(移除移动端点击延迟)引起的冲突,由于ios11 之后修复了移动点击300ms延迟。**

解决方案:

一、在node_module里找到fastClick文件,然后找到focus方法,加一句focus方法即可解决:

FastClick.prototype.focus = function(targetElement) {
    var length;
    if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
        length = targetElement.value.length;
        targetElement.setSelectionRange(length, length);
        // 修复bug iOS 11.3以上不弹出键盘,加上聚焦代码,让其强聚焦弹窗键盘
        targetElement.focus();
    } else {
        targetElement.focus();
    }
};

二、在main.js下加入以下代码:

const str= navigator.userAgent.toLowerCase()
const ver=str.match(/cpu iphone os (.*?) like mac os/)
 
if (!ver) { // 非IOS系统
  // 引入fastclick 做相关处理
  FastClick.attach(document.body)
} else {
  if (parseInt(ver[1])< 11) {
    // 引入fastclick 做相关处理
    FastClick.attach(document.body)
  }
}

小阿飞
16 声望1 粉丝

纯色白衬衫