Why doesn't my form post when I disable the submit button to prevent double clicking?

后端 未结 10 1268
广开言路
广开言路 2020-12-31 19:06

Like every other web developer on the planet, I have an issue with users double clicking the submit button on my forms. My understanding is that the conventional way to han

10条回答
  •  伪装坚强ぢ
    2020-12-31 19:30

    "Disabling" HTML controls doesn't always produce consistent behavior in all major browsers. So I try to stay away from doing that on the client-side, because (working with the ASP.NET model) you need to keep track of element's state on client and server in that case.

    What I'd do is move button off the visible part of the window by switching the button's className to a CSS class that contains the following:

    .hiddenButton
    {
      position: absolute;
      top: -1000px;
      left: -1000px;
    }
    

    Now, what to put in place of the button?

    1. Either an image that looks like a disabled button
    2. Or just plain text that says "Please wait..."

    And this can be done the same way but in reverse. Start with the element being hidden at page load and then switch to a visible className on form submit.

提交回复
热议问题