1

私のアプリでボタンをクリックすると、いくつかのデータベースの変更を行うビューが呼び出され、html をレンダリングする新しいビューにリダイレクトされます。通常、ユーザーがリンクをクリックすると、数秒間に 2 回から 3 回、誤ってクリックしてしまいます。同じ呼び出しが 10 秒以内に行われた場合、ビュー呼び出しをブロックしたい。もちろん、データベースをチェックインすることでそれを行うことができますが、django でデコレータを使用することで、より高速なソリューションが得られることを望んでいました。

4

3 に答える 3

2

これは役立つはずです。クリック時にボタンを無効にし、操作の完了後に有効にする JavaScript です。

$(document).ready(function () {
    $("#btn").on("click", function() {
        $(this).attr("disabled", "disabled");
        doWork(); //this method contains your logic
    });
});

function doWork() {
     alert("doing work");
     //actually this function will do something and when processing is done the button is enabled by removing the 'disabled' attribute
     //I use setTimeout so you can see the button can only be clicked once, and can't be clicked again while work is being done
     setTimeout('$("#btn").removeAttr("disabled")', 1500);
}

詳細はこちら

于 2013-09-27T23:10:25.870 に答える