美文网首页
fastclick在ios手机focus输入框异常

fastclick在ios手机focus输入框异常

作者: Mr老朝 | 来源:发表于2022-01-26 19:13 被阅读0次
    import FastClick from 'fastclick';
    
    var deviceIsWindowsPhone = navigator.userAgent.indexOf('Windows Phone') >= 0;
    var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;
    
    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();
        }
    };
    
    export default FastClick;
    
    

    相关文章

      网友评论

          本文标题:fastclick在ios手机focus输入框异常

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