JS實現點選後倒計時確認
阿新 • • 發佈:2018-11-19
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) } }