event.preventDefault() not working in Mozilla or IE

前端 未结 5 2128
陌清茗
陌清茗 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条回答
  •  北恋
    北恋 (楼主)
    2021-01-23 05:25

    Set the console to persist the console.log. You should see a JavaScript error

    e.preventDefault();  //<--trying to prevent the form from submitting
    

    Where is e defined?

    function checkLogin()  <-- No e defined
    

    You will have an error which means the form will submit since nothing prevented it from stopping.

    function checkLogin(e) {
        e = e || window.event;
    

    and since it is not a jQuery wrapped event object, you need to do it like

    $.Event(e).preventDefault();
    

提交回复
热议问题