移动端兼容问题

mac2025-11-04  1

ios对new Date() 的兼容问题

问题: var d = new Date(“2019-11-11 17:39:00”); 在ios上返回 invalid Date原因: ios里不支持 ‘-’ 连接的日期解决: 将日期转换为 ‘/’ 连接的 var d = new Date(“2019-11-11 17:39:00”.replace(/-/g, “/”));

移动端弹出软键盘导致input光标错位

原因: 移动端在点击input输入的时候软键盘弹出,整个页面被键盘往上挤压,然而光标的位置也被挤压,收起软键盘的时候页面恢复,但是光标还是在原来input的位置,就导致光标不在该在的地方,整个页面呈现无法点击的状态

解决: 在软键盘收起(也就是失焦)的时候scrollTop回顶部

$("input").blur(function(){ setTimeout(function(){ var scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0; window.scrollTo(0, Math.max(scrollHeight - 1, 0)); },100) })

IOS收起软键盘底部留白

同上

var scrollTimer = -1; $("input").focus(function () { clearTimeout(scrollTimer); }) $("input").blur(function () { clearTimeout(scrollTimer); scrollTimer = setTimeout(function () { window.scroll(0, 0); // IOS软键盘收起后底部留白问题解决 }, 200); })
最新回复(0)