Javascript iPad Return Key event? - Stack Overflow

On a JavaScript page, I pop up an alert if the user hits the enter key by usingif(evt.keyCode == 13){al

On a JavaScript page, I pop up an alert if the user hits the enter key by using

if(evt.keyCode == 13){
    alert("Return Key Pressed");
}

but the event does not fire when I hit the return key on the iPad. How do I catch the event?

On a JavaScript page, I pop up an alert if the user hits the enter key by using

if(evt.keyCode == 13){
    alert("Return Key Pressed");
}

but the event does not fire when I hit the return key on the iPad. How do I catch the event?

Share Improve this question edited Oct 1, 2013 at 20:51 CommunityBot 11 silver badge asked May 9, 2012 at 2:54 RolandoRolando 62.8k104 gold badges281 silver badges422 bronze badges 2
  • Check if the target element is focused. – Derek 朕會功夫 Commented May 9, 2012 at 2:56
  • How to check and if not focused, how do I set it focused? Note that the element I am using is a textbox. – Rolando Commented May 9, 2012 at 3:07
Add a ment  | 

2 Answers 2

Reset to default 3

The iPad keyboard does fire the keypress event with a key code of 13 if you press return. This sounds like you've got something else going awry

Here's a quick jsfiddle to verify with: http://jsfiddle/359wG/

According to https://api.jquery./keypress/

The keypress event is sent to an element when the browser registers keyboard input. This is similar to the keydown event, except that modifier and non-printing keys such as Shift, Esc, and delete trigger keydown events but not keypress events. Other differences between the two events may arise depending on platform and browser.

A keypress event handler can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form controls can always get focus so are reasonable candidates for this event type.

I moved my return-key listener to an anchor tag, which on IPad is treated as a 'focusable element' similar to form controls.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744266175a4565876.html

相关推荐

  • Javascript iPad Return Key event? - Stack Overflow

    On a JavaScript page, I pop up an alert if the user hits the enter key by usingif(evt.keyCode == 13){al

    7天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信