Javascript iPad Return Key event?

前端 未结 2 631
无人共我
无人共我 2021-01-21 09:54

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

相关标签:
2条回答
  • 2021-01-21 10:37

    According to https://api.jquery.com/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.

    0 讨论(0)
  • 2021-01-21 10:43

    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.net/359wG/

    0 讨论(0)
提交回复
热议问题