简体   繁体   中英

How to use return in addEventListener in Javascript?

I use include login page in header of my site and when I use onSubmit="return login();" not working this function how can get true or false with this code:

document.getElementById("loginform").addEventListener("submit", login);
document.getElementById("loginform").addEventListener("submit", login());

I thing you're missing () in the second parameter. If you don't have a function for the login make the function inside the second param

document.getElementById("loginform").addEventListener("submit", function (e) {
  if("Your Desired Conditions") {
      e.preventDefault();
  }
  else{
      function(e){ return true; }  
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM