JSFiddle - React, Tailwind, and code Playground

by micmic

HTML

<input type="button" id="bouton" value="lancer" onclick="decompte(10)" />

JavaScript

function decompte(duree) {
    var regex = /^.+\(([0-9]+)\).*$/;
    var x = document.getElementById("bouton");
    var nb = regex.exec(x.getAttribute("onclick"));
    //alert(nb[1]);
    x.value = ".."+duree+"...";
    var cpt = duree;
    var t = setInterval(function () {
        --cpt;
        if(cpt >=0){
            x.value = '...' +cpt + '....';
        } 
        else{
            clearInterval(t);
            x.value="lancer";
        }
    }, 1000);
}