1. 程式人生 > >JS實現點選後倒計時確認

JS實現點選後倒計時確認

html:

<button  id="test01" class="savebtn" onclick="test01F()" type="button" >test</button>

js:

 var time = 10;
 var timeSet;
        function test01F(){
            //var test = $("#test01").text();
            time = time - 1;
            console.log("newTime:" + time);
            var a = $("#test01");
            a.attr("disabled","disabled");
            if(time == 0){
            	time = 10;
            	a.val("確定");
            	a.removeAttr("disabled")
                //移除計時器
                //clearTimeout(timeSet);
            }else{
            	a.val(time);
	            timeSet = setTimeout(function() {
	            	test01F()
	            },1000)
            }
            
        }