簡體   English   中英

單擊后禁用提交按鈕將阻止在 Chrome 中提交表單

[英]Disabling submit Button after click will prevent submiting form in Chrome

我最近遇到了,至少對我來說,有趣的錯誤。 如果表單中沒有驗證錯誤,我們已經制作了禁用提交按鈕的 JS 以防止多個表單發送等。這在 Firefox 中工作得很好。 但是,這在 chrome 中無論如何都行不通。

如果一切正常,這是我驗證表單和禁用按鈕的邏輯。

    $('body').on('click', "button[type='submit']", function (evt) {
        MessageBox.RemoveAllBoxes();

        if (!CustomDynamicValidation()) {

            //Something went wrong
            return false;
        }
        
        //Everything is ok. Disable button and send
        $(this).attr('disabled', true);
        return true;
    });

這適用於 Firefox。 單擊並發送表單后,按鈕被禁用。 在 Chrome 中按鈕被禁用但未發送表單。

我認為如果我在 Timeout 中設置 disable ,它甚至可以在 chrome 中開始工作。 喜歡:

    $('body').on('click', "button[type='submit']", function (evt) {
        var submitButton = $(this);

        MessageBox.RemoveAllBoxes();

        if (!CustomDynamicValidation()) {

            //Something went wrong
            return false;
        }
        
        //Everything is ok. Disable button and send
        setTimeout(function () { $(button).attr('disabled', true); }, 0);
        return true;
    });

我的問題是為什么會這樣? 為什么即使 chrome 工作零延遲也需要超時? 或者,是否有更優雅的解決方案?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM