How do I prevent an on.submit event from changing/reloading the page?

后端 未结 1 1151
长发绾君心
长发绾君心 2020-12-11 19:45

In Javascript when I provide an onSubmit function, and I return \'false\' from the function, it prevents the page from changing/reloading.

相关标签:
1条回答
  • 2020-12-11 20:31

    Within the on.submit.add(...) callback, you will receive the Event as an argument. The Event object provides a preventDefault() method to prevent or cancel the default action.

    It can be used as follows:

    querySelector('#myForm').onSubmit.listen((Event e) {
      // ... your code here
      e.preventDefault();
    });
    
    0 讨论(0)
提交回复
热议问题