美文网首页让前端飞Web前端之路
移动端iOS中input聚焦不灵敏(需点击多次)

移动端iOS中input聚焦不灵敏(需点击多次)

作者: 小西瓜Ly | 来源:发表于2019-10-22 10:23 被阅读0次

可能情况1:检查是否使用了FastClick,如果使用了在main.js中增加以下代码即可。

FastClick.attach(document.body);
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();
  }
}

可能情况2:App.vue中设置了-webkit-user-select: none;影响到了input,解决方法:

*:not(input,textarea), *:before:not(input,textarea), *:after:not(input,textarea) {
    -webkit-user-select: none; 
  }

相关文章

网友评论

    本文标题:移动端iOS中input聚焦不灵敏(需点击多次)

    本文链接:https://www.haomeiwen.com/subject/woofvctx.html