html phonegap android : numeric soft keyboard has next instead of go button

后端 未结 2 1725
鱼传尺愫
鱼传尺愫 2021-01-02 01:14

This is driving me crazy and I can\'t find the answer anywhere.

I have forms in my phonegap app. If the input type=\"text\", the text keyboard pops up and \"go\" is

相关标签:
2条回答
  • 2021-01-02 01:44

    You can detect the next keyboard press by using the following bind in JQuery:

    $('input').on('keydown', function(e){
        if(e.which === 9) {
            //your code here
        }
    });
    

    The 'next' button emulates the tab keypress event on a keyboard, which is key code 9. Unfortunately, keypress and keyup events do not detect the next key event, so you need to bind it on keydown.

    Hope that helps!

    0 讨论(0)
  • 2021-01-02 01:47

    Okay, now I do have something that looks like an answer and quacks like an answer.

    It's a horrible hack, and I am experiencing some side-effects at this point, but it's a small leap for mankind anyway.

    Add an invisible text input to your form, which automatically submits the form as soon as it receives focus. Since it can only receive focus from the user pressing 'Next' or tabbing from the last number field, there should be a pretty solid logic in the user sequence.

    <input type='text' style="opacity:0;" onfocus="javascript:$('#thisForm').submit();">
    

    The side effects are:

    • the hidden form field will briefly be visible. You can avoid this by using the onfocus handler to also re-focus on the number field that was just left. Or you can set the width of the input to 0. The latter works best for me.
    • if you're using jQueryMobile like me, you're inviting horrible page transition ugliness on yourself, so if your form is in a dialog and submitting the form closes the dialog, be sure to set the dialog transition (when it is being opened from a previous screen) to 'none'.
    0 讨论(0)
提交回复
热议问题