一个 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();
}
};