https://www.daimajiaoliu.com/series/solution/46f998680100404

disabled

通过 Javascript 防止重复点击提交按钮,通常的做法是将按钮禁用通过 disabled 属性实现

jquery

  1. $("form").submit(()=> {
  2. $(":submit", this).attr("disabled","disabled");
  3. });

react

  1. function App() {
  2. const [loading, setLoading] = useState(false);
  3. async function onSubmit() {
  4. setLoading(true);
  5. const res = await $ajax();
  6. if (res.code) {
  7. setLoading(false);
  8. }
  9. }
  10. return (
  11. <Form>
  12. <Button
  13. disabled={loading}
  14. type="primary"
  15. onClick={onSubmit}
  16. >提交</Button>
  17. </Form>
  18. );
  19. }