如何在 iOS 中使用 readOnly 属性聚焦 <input>?

How to focus <input> with readOnly attribute in iOS?

我尝试使用 readOnly 属性来防止自动填充输入。我为 focus 事件添加处理程序,删除 readOnly 属性,为 blur 事件添加处理程序,添加 readOnly 属性。

但它在 iOS 中的任何浏览器中都不起作用。我在 中找到了这个问题的可能解决方案。但是当我尝试一个接一个 <input> 时,此解决方案不起作用。例如,当我在 <button> 之后尝试 focus <input> 时,一切正常。

知道如何解决吗?

实例:https://codesandbox.io/s/readonly-for-prevent-autofill-76ecn

 <input ontouchstart="this.removeAttribute('readonly');" onfocus="this.removeAttribute('readonly');" readonly>

嗯……5 小时