iPad Safari - 让键盘消失
在 iPad Safari 浏览器中,当我将焦点从文本框更改为下拉菜单时,键盘仍然保留...是否有某种方法(也许使用 Javascript)可以在用户从文本框模糊时隐藏键盘?
间接地说,我正在寻找相当于(但在 Mobile Safari 中)
[tempTextField resignFirstResponder];
In iPad Safari browser, when I change focus from a textbox to a dropdown, the keyboard still remains... Is there some way (maybe with Javascript) I can hide the keyboard when user blurs from the textbox?
Indirectly speaking, I am looking for a equivalent of (but in Mobile Safari)
[tempTextField resignFirstResponder];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我在 http://uihacker 找到了解决方案。 blogspot.com/2011/10/javascript-hide-ios-soft-keyboard.html。本质上,只需这样做(这对我有用):
I found the solution for this at http://uihacker.blogspot.com/2011/10/javascript-hide-ios-soft-keyboard.html. Essentially, just do this (it worked for me):
我的 iPad 装有 iOS 5.0.1,在成功登录我的网站后没有隐藏键盘。我通过在成功登录后简单地执行 javascript 命令来解决
,现在键盘已正确隐藏:-)
I had iPad with iOS 5.0.1 not hiding the keyboard after successful login on my site. I solved by simply executing the javascript command
after successful login and now the keyboard is correctly hidden :-)
我知道这是一个稍微老一点的问题,但我今天发现了答案,而且答案非常简单......我花了比我愿意承认的更多的时间来解决这个问题;)
为了防止显示键盘:
当你想做一些类似使用 jQuery UI 日期选择器之类的事情时...
添加一个 readonly 属性,如下所示:
如果你想留意关闭 JS 的人,你可以随时忽略属性并将其添加到您的代码中:
希望这会有所帮助。
这是一个演示这个概念的 jsFiddle: http://jsfiddle.net/3QLBz/5/
I know this is a slightly older question, but I discovered the answer today for this, and the answer is embarrassingly simple... I spent way more time than I would like to admit figuring this out ;)
To prevent showing the keyboard on:
for when you want to do something like use a jQuery UI datepicker...
add a readonly attribute like so:
If you are trying to be mindful of people with JS turned off, you could always leave off the attribute and add it in your code:
Hope this helps.
Here is a jsFiddle demonstrating the concept: http://jsfiddle.net/3QLBz/5/
与 iPad 上的 jquery UI 日期选择器配合使用
works with jquery UI datepicker on IPad
本质上,当输入失去焦点时,iPad、iPhone 键盘应该消失。
我发现在移动/平板设备上
Safari 仅处理具有
cursor:pointer
的元素的点击事件财产。
我终于在移动/平板电脑设备的 body 标签上添加了
cursor:pointer
,它的工作方式就像一个魅力。样品很少
Natively, iPad, iPhone keyboard should disappear when the input looses focus.
I figured out on mobile/tablet devices that
Safari only handles click event for elements having
cursor:pointer
property.
I've finally added
cursor:pointer
on the body tag for mobile/tablet devices and it works like a charm.Little sample
没有 jQuery 的版本:
Version without jQuery:
我在另一个文本字段上调用 .focus() ,键盘消失了。我正在使用 Sencha 触摸框架,我指的文本字段是 Ext.Text 对象。
我知道这违反直觉,但它似乎对我有用
I call .focus() on another textfield and the keyboard disappears. I'm using the Sencha touch framework, the textfield im referring to is an Ext.Text object.
I know this is counter-intuitive, but it seems to work for me
如果您不想模糊输入,可以使用
inputMode
控制虚拟键盘。将其设置为none
会隐藏键盘。将其设置为其他内容会显示相应的键盘。看看这个演示:https://codepen.io/waterplea/pen/dyLjaQP
If you do not want to blur your input, you can control virtual keyboard with
inputMode
. Setting it tonone
hides keyboard. Setting it to something else shows the corresponding keyboard. Check out this demo:https://codepen.io/waterplea/pen/dyLjaQP
您可以使用上面的代码。第一行和第四行用于该文本字段。它适用于 iPhone,但不适用于 Android。我尝试过 Iphone 3gs 和三星 Galaxy s2。
You can use codes above. First and Forth lines are for that textfield. It works on iphone but it doesnt work on Android. I tried Iphone 3gs and samsung galaxy s2.
根据 Apple Safari 文档,当您选择下拉菜单(选择列表)时,iOS 会关闭键盘并显示本机 iOS 选择控件。确保在下拉列表中使用 SELECT 元素
,并尝试将其添加到页面的元标记中
According to Apple Safari documentation, when you select a dropdown (select list) the iOS dismisses the keyboard and displays native iOS select control. Make sure you use SELECT element for your dropdown list
and also try adding this to your meta tags for the page