zoukankan      html  css  js  c++  java
  • vue引入fastClick导致的输入框点击无响应问题

    混合开发过程中,iOS引用前端界面之后,界面点击会默认产生一个300毫秒的延时效果,为了解决这个问题,引入fastClick,但是当界面引入fastClick之后,会产生输入框点击无法获取焦点问题,只有双击或者长按的时候才能使input输入框获取到焦点,该问题是由于引入fastClick导致的,解决方案如下:

    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') {

        length = targetElement.value.length;

        targetElement.focus();

        targetElement.setSelectionRange(length, length);

      } else {

        targetElement.focus();

    }

    };

    再引入fastClick的js中加入如上代码即可解决input输入框点击不能获取焦点的问题

  • 相关阅读:
    四、git学习之——分支管理、解决冲突
    四、git学习之——远程仓库
    异常
    内部类
    接口
    Java三大特性之多态
    抽象类、抽象方法、final、Object类
    Java三大特性之继承
    Java三大特性之封装
    代码块、Package、Import
  • 原文地址:https://www.cnblogs.com/chenzxl/p/11567384.html
Copyright © 2011-2022 走看看