简体   繁体   中英

This my button and function for it. My question is, after click that button.. how to make it disable for 30 mins?

Down there is my button n function for that button in php, how to add disable button for 30 mins after clicking on it? I need help for it because im still newbie on php coding..


<button class="btn btn-primary" style="width: 200px; outline: none;" id="testar" onclick="enviar()">START</button>

This my function:


      <script title="ajax do checker">
        function enviar() {
            var linha = $("#lista").val();
            var linhaenviar = linha.split("\n");
            var total = linhaenviar.length;
            var ap = 0;
            var ed = 0;
            var rp = 0;
            linhaenviar.forEach(function(value, index) {
                setTimeout(
                      function() {
                                var sec = $("#sec").val();
                        $.ajax({
                            url: 'g3api.php?lista=' + value,
                            type: 'GET',
                            async: true,
                            success: function(resultado) {
                                if (resultado.match("Approved")) {
                                    removelinha();
                                    ap++;
                                    aprovadas(resultado + "");
                                }else if(resultado.match("CCN")) {
                                    removelinha();
                                    ed++;
                                    edrovadas(resultado + "");
                                }else {
                                    removelinha();
                                    rp++;
                                    reprovadas(resultado + "");
                                }
                                $('#carregadas').html(total);
                                var fila = parseInt(ap) + parseInt(ed) + parseInt(rp);
                                $('#cLive').html(ap);
                                $('#cWarn').html(ed);
                                $('#cDie').html(rp);
                                $('#total').html(fila);
                                $('#cLive2').html(ap);
                                $('#cWarn2').html(ed);
                                $('#cDie2').html(rp);
                            }
                        });
                    }, 5000 * index);
            });
        }
        function aprovadas(str) {
            $(".aprovadas").append(str + "<br>");
        }
        function reprovadas(str) {
            $(".reprovadas").append(str + "<br>");
        }
        function edrovadas(str) {
            $(".edrovadas").append(str + "<br>");
        }
        function removelinha() {
            var lines = $("#lista").val().split('\n');
            lines.splice(0, 1);
            $("#lista").val(lines.join("\n"));
        }
    
        function iloveyou(){
        alert('PEKPEK')}
    </script>

My question is: How to make the button disabled for 30 minutes after it's clicked?

button.addEventListener('click', () => {
    if (localStorage.getItem('clicked') === 'true') return;
    localStorage.setItem('clicked', 'true');
    button.disabled = true;

    setTimeout(() => {
        localStorage.removeItem('clicked');
        button.disabled = false;
    }, 60000 * 10);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM