移动端-vue 项目在 iPhone 微信浏览器里点击 input 框唤起软键盘不灵敏问题

一个 vue 项目,使用了 fastclick.js, 在 iPhone 手机的微信浏览器中打开,点击输入框不灵敏,经常需要点击多次才能聚焦的问题

### 找到 fastclick.js 下面一段源码,添加 targetElement.focus(); 代码即可,如果使用 webpack, 修改 node_module 里 fastclick 源码也一样
/**
  * @param {EventTarget|Element} targetElement
  */
 FastClick.prototype.focus = function(targetElement) {
     var length;

     // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
     if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') {
         length = targetElement.value.length;
         targetElement.focus();    // 这是添加的代码
         targetElement.setSelectionRange(length, length);
     } else {
         targetElement.focus();
     }
 };
相关链接
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。