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

后端 未结 10 1318
广开言路
广开言路 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:50

    We use the following JQuery script, to disable all buttons (input type=submit and button), when one button is clicked.

    We just included the script in a global JavaScript file, so we don't have to do remember anything when creating new buttons.

    $(document).ready(function() {
        $(":button,:submit").bind("click", function() {
            setTimeout(function() {
                $(":button,:submit").attr("disabled", "true");
            }, 0);
        });
    });
    

    This script could easily be extended with a check for Page_ClientValidate().

提交回复
热议问题