最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to detect pressing enter on mobile device keyboard using jquery? - Stack Overflow

programmeradmin5浏览0评论

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? My code ;

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

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

       });
    </script>   

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? My code ;

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

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

       });
    </script>   
Share Improve this question asked Sep 17, 2014 at 8:11 Fikret SavaşFikret Savaş 1274 silver badges12 bronze badges 1
  • Do you see any error in javascript console? Your sure that modal() is defined when code executes? – Boris Zagoruiko Commented Sep 17, 2014 at 8:14
Add a ment  | 

2 Answers 2

Reset to default 7

Normally, within a form, the enter key on a mobile device submits the form. 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?

Well, on touch devices there is no such event as keyup as far as I know. At least in iOS: https://developer.apple./library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

Consider using form's submit event instead.

发布评论

评论列表(0)

  1. 暂无评论