event.preventDefault() not working in Mozilla or IE

前端 未结 5 2134
陌清茗
陌清茗 2021-01-23 04:31

I\'m finally at the point of testing my site in other browsers (built it mostly in Chrome). Unfortunately, a lot of stuff seems to function differently. I\'ll begin with the v

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-23 05:25

    Unfortunately I was unable to do as I had hoped in the title as I could never successfully prevent the submit in all four browsers (Mozilla was a persistent holdout).

    What I ended up doing, then, was the following:

    1.) In my HTML, I changed the boundaries of the so that it only contained the inputs, but the 'Submit' button was OUTSIDE of

    2.) Then, instead of have like I had, I moved "return checkLogin()" down to the submit button (now outside of the form) and changed it to 'onclick'.

    3.) This way, I didn't need any preventDefault() as there was no default to occur. I simply went to the ajax request, and in the 'return true' case, set it to do $('#mainform').submit();

    Note: By doing this, I was also able to make the ajax request no longer asynchronous, which everyone says is good (I'm still new so not as sure of its importance).

    Hopefully this helps anybody who comes across the same issue.

提交回复
热议问题