How can I prevent the Go button on iPad/iPhone from posting the form

后端 未结 6 1507
北海茫月
北海茫月 2020-12-31 00:52

I have a dynamic form that is to be displayed using an iPad.

This form has a couple of radio buttons and some text fields and one submit button.

In an iPad t

6条回答
  •  半阙折子戏
    2020-12-31 01:23

    Here's an additional answer, in case anyone winds up chasing this issue like I did.

    Provided you're using jQuery, the following snippet should prevent the "Go" button from triggering a form submission (at least it does on Nexus 7's Chrome on Android 4.2.2; YMMMV). Also, note that if you want to allow the "Enter" key to work on any of the input types below, this will prevent that from happening.

    $(document.body).on('keydown', 'input:text, input[type=password], input[type=email]',     
        function (e) { 
            // Android maps the "Go" button to the Enter key => key code 13
            if (e.keyCode == 13) {
                return false; 
            }
        });
    

    Edit: It seems this bug breaks keyup/keydown in Chrome in Android > 4.3, in which case this fix will no longer work in some circumstances.

提交回复
热议问题