html button 點擊 顯示倒計時秒數


如下:

 

<html>
<body>
        <input type="button" value="click" id="click" onclick="foo(this, 10000);"/>
</body>

<script>
function foo(obj, time) {
    obj.disabled = true;

    setTimeout(function() {
        var x = setInterval(function(){
                time= time - 1000; //reduce each second
                obj.value = (time/1000)%60;
                if(time==0){
                        clearInterval(x);
                        obj.value = "retry";
                        obj.disabled = false;
                }
        }, 1000);
    }, time-10000);
}
</script>
</html>

 

 

參考: 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM