IOS上11.3以上的input输入问题

1.fastclick在ios 11.4以上的bug解决
场景:在该版本的某一个输入框输入字符后,点击输入法上面的"完成"按钮,再点击该页面的其他输入框或者当前输入框都无效,需要长按才有效果;
解决办法:
修改fastclick源码,具体修改如下

/**
     * @param {EventTarget|Element} targetElement
     */
    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' && targetElement.type !== 'email') {
            length = targetElement.value.length;
            targetElement.setSelectionRange(length, length);
            targetElement.focus();//加上这一句
        } else {
            targetElement.focus();
        }
    };

原因:强制触发选中的文本框focus,这样就能持续输入字符


2.ios 11.4以上弹出框里面的文本框输入字符后失焦,点击确定按钮无效
// 原因是,当软键盘隐藏的时候,遮罩层回到原位,但是body未回到原来位置,需要手动触发一下。下面是一种解决方案,如果还有更好的方案欢迎提出:

(/iphone|ipod|ipad/i.test(navigator.appVersion)) && document.addEventListener('blur', function (e) {
// 滚动时 让body的底部与视图容器底部对齐
// 页面(容器)可滚动时有效
    document.body.scrollIntoView(false)
}, true)


 

你可能感兴趣的:(Web前端)