- 近期發現項目中關於輸入框在ios上點擊失效,多次點擊纔可以獲取焦點的問題,那麼導致這個問題所在的原因是因爲項目中引入了FastClick 這個是解決移動端延遲300毫秒的優化
當使用FastClick 時,輸入框在ios上點擊輸入調取手機自帶輸入鍵盤不靈敏,有時候甚至點不出來。而安卓上完全沒問題。這個原因是因爲FastClick的點擊穿透。解決方法如下:
const FastClick = require('fastclick')
FastClick.prototype.focus = function (targetElement) { let length; if (targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { length = targetElement.value.length; targetElement.focus(); targetElement.setSelectionRange(length, length); } else { targetElement.focus(); } };