admin管理员组

文章数量:1325137

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.

本文标签: javascriptHow to detect pressing enter on mobile device keyboard using jqueryStack Overflow