【问题标题】:How to detect pressing enter on mobile device keyboard using jquery?如何使用 jquery 检测移动设备键盘上的回车键?
【发布时间】:2014-11-11 04:30:39
【问题描述】:

我正在使用 Bootstrap。当在文本框中按 enter 时,使用 Bootstrap 打开 Modal 弹出窗口。但是当我使用手机时,我无法检测到按 enter。如何检测到它?你能帮帮我吗? 我的代码;

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

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

       });
    </script>   

【问题讨论】:

  • 您在 javascript 控制台中看到任何错误吗?您确定modal() 是在代码执行时定义的吗?

标签: javascript jquery twitter-bootstrap


【解决方案1】:

通常,在表单中,移动设备上的回车键提交表单。我建议在提交处理程序中添加一些逻辑:

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

其他信息

见:HTML: Why does Android browser show "Go" instead of "Next" in keyboard?

【讨论】:

【解决方案2】:

好吧,据我所知,在触摸设备上没有 keyup 这样的事件。至少在 iOS 中:https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

考虑改用表单的submit 事件。

【讨论】:

    猜你喜欢
    • 2010-11-02
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 2017-07-25
    • 2014-07-14
    • 1970-01-01
    • 2017-06-02
    • 2014-09-14
    相关资源
    最近更新 更多