每天只能点击一次按钮

Only can Click the Button for one time per day

我有一个数值为100的按钮。页面上会显示一个总数。当我点击 "Add 100" 时,它会更新并显示在页面上。我希望按钮每天只点击一次。例如,您不能再次单击该按钮。这是我的 html 代码。我怎样才能让按钮每天只能点击一次? (24 小时)?

   <div>Total : <span id="total">0</span></div>
   <input class="add" data-amount="100" type="button" value="Add 100" />


$(document).ready(function() {
$('.add').click(function() {
 $('#total').text(parseInt($('#total').text()) + 
 parseInt($(this).data('amount')));
 });
})

您需要使用服务器端 JavaScript 使其在您关闭页面时正常工作,但如果页面没有关闭或重新加载,曾经,你这样做:

var dayClicked = true;

$("#button").click(function() {
    if (dayClicked) {
        alert("Error!");
    }
    else {
        variable += 1;
        dayClicked = false;
    }
    setTimeout(function() {
        dayClicked = true;
    }, 86400000);
});

这会向 variable 添加 1,然后使 #button 元素显示第二天的错误消息(86400000 秒)。