表单在ios下输入框必须重压或长按才能唤起软键盘

解决方案:

一、在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)
}
}

经个人使用,第一种方法有效

https://segmentfault.com/a/1190000020069345

posted @ 2019-07-28 09:09  BloggerSb  阅读(496)  评论(0编辑  收藏  举报