简体   繁体   English

移动Safari键盘表单提交

[英]Mobile Safari Keyboard Form Submission

I have a basic form with a search input and a submit button within. 我有一个基本form其中包含search input和一个submit button When focus takes place in the input , the keyboard is displayed as expected. input出现焦点时,将按预期显示键盘。 When I press the button , the form submit event occurs, in which I call event.preventDefault() and instead make an ajax call. 当我按下button ,将发生表单提交事件,在该事件中,我调用event.preventDefault()并进行一个ajax调用。 However, when I press the search button on the keyboard, the keyboard just hides and no submit event occurs. 但是,当我按键盘上的“ 搜索”按钮时,键盘只是隐藏了,没有提交事件发生。

Why doesn't the form submit when I press search on the keyboard? 当我按键盘上的搜索键时,为什么表单不提交? How can I trigger this event to happen via the keyboard search button? 如何通过键盘搜索按钮触发此事件发生?

Thanks. 谢谢。

The keyboard search button must be bound to a keypress event and has the keycode of 13 . 键盘搜索按钮必须绑定到按键事件,并且keycode13

Basically, listen to keypress events and return all calls except for e.which === 13 基本上,听keypress事件并返回除e.which === 13之外的所有呼叫

$('input').on('keypress', function ( e ) {
    if ( e.which !== 13 ) {
        return;
    }

    // ajax code
}

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

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