开发者

Hide The iPad Keyboard By Hitting the Return Key

开发者 https://www.devze.com 2023-02-07 02:59 出处:网络
Is it possible to hide the iPad keyboard after entering a value into an input field on a website by hitting the Return key without forcing the user to use the Hide Keyboard key?

Is it possible to hide the iPad keyboard after entering a value into an input field on a website by hitting the Return key without forcing the user to use the Hide Keyboard key?

Is there something in HTML or jQuery that I can code into my page to force this behavior?

(P.S. Based of my hours of research online, it seems impossible with the w开发者_Python百科ay the iPad currently functions. But I would really appreciate any info!)


You can hide the keyboard by calling the blur handler on the text input:

$("#textField").blur();

where #textField is a selector to select the text input. You need to put this line in the right place, which depends on how the form is coded, and in most cases would be in the form's submit handler.


The easiest answer to your question on any input regardless of form submit would be

$('input').keyup(function(event) {
    if (event.which === 13) {
      $(this).blur();
    }
});

Probably a little easier to put in the right place.

Return = Enter key


This is probably what you're after

How do I cancel a text field edit in a UIWebView?


Try calling resignFirstResponder on the text field. That should dismiss the keyboard. I know this works on iPhone, and don't know of a reason it wouldn't on iPad, though I don't recall having tried that specifically on that platform.

0

精彩评论

暂无评论...
验证码 换一张
取 消