开发者

BlackBerry JavaScript support of keycodes/keypresses

I'm new to dealing with BlackBerry devices. I'm currently running into a JavaScript issue on a 9700 and trapping keypress events and getting a proper keycode.

I have this javascript:

function numbersonly(e) {
    var key
    if(window.event) {
        key = window.event.keyCode; // IE
    }else{
        key = e.which;开发者_开发知识库 // Firefox
    }

    alert('keycode : ' + key);

}

And it's attached to an input field via an unobtrusive addEvent script.

On a standard desktop browser (Firefox and IE), it does what you'd think it does...pressing a key will show the keycode via the alert.

On a blackberry, however, pressing a key does one of two things:

  • if the key presses is the numbers 1 through 9, nothing happens.
  • if it's any other key, the keyCode is 'undefined'.

Any idea what's going on? I assume it's a limitation of the BlackBerry JavaScript support.

UPDATE:

Tested this on a 9800 Simulator as well, which is running OS6. Problem doesn't exist there. So this is either an issue with BlackBerry OS5 or BlackBerry's physical keyboard.


I'm not sure if the event variable is set when you add an inline event handler.

Have you tried setting the event-handler from javascript. So something like

document.getElementById('mytextelement').onkeypress = keytest;


Try using e.keyCode instead of e.which

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜