有没有办法避免在手机游戏中显示键盘

El *_*ser 6 html safari mobile mobile-safari

例如,如果我有

<input type="text" id="myid">
Run Code Online (Sandbox Code Playgroud)

我正在使用ipad,当我专注于此输入时,ipad会自动显示键盘.有没有办法避免这种情况?谢谢

Jon*_*ski 12

是的,只需将元素设为只读即可

<input type="text" id="myid" readonly="readonly" />
Run Code Online (Sandbox Code Playgroud)

请注意,这不适用于该元素.我相信这可能是一个错误.


BeW*_*ned 2

不要\xe2\x80\x99 不要让焦点转到该字段。使用事件处理程序来防止默认行为。\n事件处理程序将如下所示:

\n\n
function onFocus(e) {\n    e.preventDefault();\n    // you could change the color of the field to indicate this is the active field.\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

您的表处理代码可以填充此字段,而浏览器不会关注它。

\n