简体   繁体   English

[PhoneGap] [Android]如何检测回车键

[英][PhoneGap][Android] How to detect enter key

I have issue with phonegap on android, i have a simple html 我在Android上的phonegap有问题,我有一个简单的html

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

and a simple javascript 和一个简单的javascript

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

When i press enter key, nothing happen, other keys work. 当我按Enter键时,什么也没有发生,其他键也起作用。 I use phonegap 2.9.0 and android 2.3.5 我使用phonegap 2.9.0和android 2.3.5

Please help me 请帮我

You can use the keycodes to detect which key was pressed. 您可以使用键码来检测按下了哪个键。 I have an example here: 我这里有一个例子:

jsFiddle jsFiddle

HTML 的HTML

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

JavaScript 的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. 这就是我在移动应用程序中执行此操作的方式,但是没有使用phonegap,因此无法肯定它将起作用,但是值得一试。

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

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

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