Html 不要为网页中的特定文本框显示 iPhone 键盘?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/317295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:47:47  来源:igfitidea点击:

Don't show iPhone keyboard for a particular textbox in web page?

iphonehtmlweb-applications

提问by Ramesh Soni

Is there any setting using which the iPhone keyboard won't appear for a particular textbox in web page? May be some css kind of setting?

是否有任何设置不会为网页中的特定文本框显示 iPhone 键盘?可能是某种 css 类型的设置?

回答by siva

you just make the input field as readonly="true"/ readonly mode so that keyboard wont appear!!

您只需将输入字段设为readonly="true"/ readonly 模式,这样键盘就不会出现!!

回答by JamesEggers

Do you want the text box to be editable for any other browser other than the iPhone? If not, have you attempted to disable the text box? I haven't tried this, nor can I recall seeing a disabled text box on a site with my iPhone; however, it may do it.

您是否希望文本框可用于除 iPhone 之外的任何其他浏览器?如果没有,您是否尝试禁用文本框?我没试过,也不记得在我的 iPhone 网站上看到一个禁用的文本框;但是,它可以做到。

If disabling the text box works, but you still only want to restrict it to the iPhone, you'll need to look at the User Agent for the iPhone. You can determine this through server side code or through JavaScript's navigator.userAgent.

如果禁用文本框有效,但您仍然只想将其限制为 iPhone,则需要查看 iPhone 的用户代理。您可以通过服务器端代码或通过 JavaScript 的navigator.userAgent.

To save a bit more time for you as well, the iPhone's user agent is as follows:

为了也为您节省更多时间,iPhone 的用户代理如下:

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3

回答by Gustavo Costa De Oliveira

If you want hide keyboard for iphone/ipad/ipod users you must identify this useragents. I recomend http://wurfl.sourceforge.net/to find different versions of these devices and then printing readonly="true" disabled="disabled"on inputs.

如果您想为 iphone/ipad/ipod 用户隐藏键盘,您必须标识此用户代理。我建议http://wurfl.sourceforge.net/找到这些设备的不同版本,然后readonly="true" disabled="disabled"在输入上打印。

回答by geoyws

Keep in mind that readonly="true" isn't required.

请记住, readonly="true" 不是必需的。

<input type="text" readonly>is enough.

<input type="text" readonly>足够。

回答by JamesEggers

I don't think you'll be able to truly disable the keyboard just like you cannot truly disable the keyboard when you browse a webpage via a PC or Mac. One trick would be to add JavaScript to intercept the OnKeyPress (or OnKeyDown) event to intercept the key stroke and cancel it based on the User Agent. I haven't tried it against the iPhone specifically but it has worked for other applications when I want to restrict the type of input on an enabled text box (i.e. canceling alpha characters in a phone number field). Since the "OnKey" events are still valid on the iPhone (as determined by sites with autocomplete like Google), the method should work.

我认为您无法真正禁用键盘,就像在通过 PC 或 Mac 浏览网页时无法真正禁用键盘一样。一种技巧是添加 JavaScript 来拦截 OnKeyPress(或 OnKeyDown)事件以拦截击键并基于用户代理取消它。我没有专门针对 iPhone 尝试过它,但是当我想限制启用的文本框上的输入类型(即取消电话号码字段中的字母字符)时,它适用于其他应用程序。由于“OnKey”事件在 iPhone 上仍然有效(由 Google 等具有自动完成功能的网站确定),因此该方法应该有效。