简体   繁体   中英

How to detect pressed key on BlackBerry using JQuery Mobile?

I am using JQuery Mobile to developing my own app for BlackBerry based on WebWorks(HTML5,CSS3,JS) tecknologies.

On my layout div i have 3 input elements. I am wont to detect BlackBerry enter key pressed in first input to focus on next input.

How i can check if hardware enter key(and other keys like "T","R","D") pressed using JQuery Mobile??

There's nothing specific to jQuery Mobile for this. You just need to add an event listener on the input and listen to the appropriate keypress event. You can find a nice explanation for them here .

Here's some sample code to get you started (not tested, you might need to debug):

$('#firstInput').keypress(function(event) {
  if ( event.which === 13 ) {
     $('#secondInput').focus();
   }
);

In the event.which , the key code gets checked (13 is for enter). Other keys have different key codes. Be careful, I remember a bug on Blackberry that it wouldn't trigger the keypress event for backspace.

Be more specific about your problem if you need more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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