gpt4 book ai didi

javascript - 绑定(bind)到 touchstart 事件导致自动对焦专注于 Mobile Safari 中的任何点击

转载 作者:太空狗 更新时间:2023-10-29 16:36:01 26 4
gpt4 key购买 nike

从理论上讲,移动版 Safari 完全不支持自动对焦 (http://caniuse.com/#feat=autofocus)。然而,我们看到了这种非常奇怪的行为,当 touchstart 事件绑定(bind)到 document 时(无论该函数是否有任何行为)使用 autofocus 的第一个输入的页面成为焦点并显示屏幕键盘。

这可以在 iOS 模拟器中使用 iOS 8 重现。这是重现问题的最小 html 和 javascript:

<html>
<head>
<script>
document.addEventListener("touchstart", function() {});
</script>
</head>

<body>
<input type="text">
<input type="text" autofocus="autofocus">
</body>
</html>

这是一个 jsfiddle:http://jsfiddle.net/qd858nob/

只需点击输入之外的任何地方,第二个输入就会自动对焦。理想情况下,我很想找到一个全局解决方案来解决这个问题,而不必从我们所有的输入元素中删除自动对焦。

最佳答案

参见 in iOS8 using .focus() will show virtual keyboard and scroll page after touch就此问题进行更广泛的讨论。看起来这是一个 iOS 8“错误”。我已经向 Apple 提交了一份报告——你能做的最好是一样的,希望它在他们的列表中上升到足够高的位置,以便尽快修复。

关于javascript - 绑定(bind)到 touchstart 事件导致自动对焦专注于 Mobile Safari 中的任何点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26683466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com