简体   繁体   English

如何使用jquery检测移动设备键盘上的Enter键?

[英]How to detect pressing enter on mobile device keyboard using jquery?

I am using Bootstrap.When press enter in textbox ,open Modal popup with Bootstrap.But when I using mobile phone ,I cant detect pressing enter.How to detect it ?Can you help me please? 我正在使用Bootstrap。在文本框中按Enter时,用Bootstrap打开Modal弹出窗口。但是当我使用手机时,我无法检测到按Enter。如何检测到它?您能帮我吗? My code ; 我的代码;

<script type="text/javascript">
     $(document).ready(function () {

           $('.form-control').keyup(function (e) {
               if (e.which == 13)   {      
                   $('.modal').modal('show');
               }
           });

       });
    </script>   

Normally, within a form, the enter key on a mobile device submits the form. 通常,在表单中,移动设备上的Enter键提交表单。 I suggest adding some logic in a submit handler: 我建议在提交处理程序中添加一些逻辑:

$("#myForm").submit(function(){
      // you're logic here
}

Additional information 附加信息

See: HTML: Why does Android browser show "Go" instead of "Next" in keyboard? 请参阅: HTML:为什么Android浏览器在键盘上显示“ Go”而不是“ Next”?

Well, on touch devices there is no such event as keyup as far as I know. 那么,在触摸设备上有没有这样的事件作为keyup据我所知。 At least in iOS: https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5 至少在iOS中: https//developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

Consider using form's submit event instead. 考虑改用表单的submit事件。

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

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