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

javascript - [PhoneGap][Android] How to detect enter key - Stack Overflow

programmeradmin4浏览0评论

I have issue with phonegap on android, i have a simple html

 <form>
  <fieldset>
    <label for="target">Type Something:</label>
    <input id="target" type="text">
  </fieldset>
</form>

and a simple javascript

$("#target").on("keypress", function(event){               
    alert(event.which);
 });

When i press enter key, nothing happen, other keys work. I use phonegap 2.9.0 and android 2.3.5

Please help me

I have issue with phonegap on android, i have a simple html

 <form>
  <fieldset>
    <label for="target">Type Something:</label>
    <input id="target" type="text">
  </fieldset>
</form>

and a simple javascript

$("#target").on("keypress", function(event){               
    alert(event.which);
 });

When i press enter key, nothing happen, other keys work. I use phonegap 2.9.0 and android 2.3.5

Please help me

Share Improve this question asked Sep 30, 2013 at 15:03 Anh HậuAnh Hậu 911 silver badge11 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

You can use the keycodes to detect which key was pressed. I have an example here:

jsFiddle

HTML

<form>
    <fieldset>
        <label for="target">Type Something:</label>
        <input id="target" type="text" />
    </fieldset>
</form>

JavaScript

$("#target").on("keypress", function(event){               
    if (event.keyCode === 13) {
        alert("The enter key was pressed");
        event.preventDefault();
    }
});

This is how I did it in my mobile app but was not with phonegap so not positive it will work, But worth a try.

   $('#target').submit(function (event) {
   event.preventDefault();
 alert(event.which);
}
发布评论

评论列表(0)

  1. 暂无评论