简体   繁体   English

用户在文本框外单击时隐藏在iOS键盘中

[英]Hiding in the iOS keyboard when user clicks outside of a text box

I'm attempting to hide the iPad soft keyboard when the user clicks outside a text field. 当用户在文本字段外单击时,我试图隐藏iPad软键盘。

Specifically somewhere on the form or body that contains no other elements. 特别是在形式或主体上不包含其他元素的某处。

Using jquery, jquery mobile, and html5. 使用jquery,jquery mobile和html5。

document.activeElement.blur();

using mattwindwer's solution (but with more details): 使用mattwindwer的解决方案(但有更多细节):

$(document).click(function() {
    document.activeElement.blur();
});

Calling focus() method on a button (even hidden buttons) hides the keyboard. 在按钮上调用focus()方法(甚至隐藏按钮)会隐藏键盘。 I have used this in my ipad web app. 我在我的ipad网络应用程序中使用过这个。

You can add a click listener to body and using target property of the event, you can determine when to hide the keyboard. 您可以向主体添加单击侦听器并使用事件的目标属性,您可以确定何时隐藏键盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM