通常這種需求在移動端比較常見,就是經過手機註冊帳號嘛,方便。
http://jsbin.com/vagocaqitu/edit?html,css,js,output
貼了個jsbin的代碼片斷,發現沒有預覽。。。
爲啥只能用jsfiddle的呢?速度太慢了吧
https://jsfiddle.net/6zr4Lb5p/embedded/result,html,css,js/javascript
javascriptvar getCode = document.getElementById('getCode'); var wait = 60; function time(btn){ if (wait===0) { btn.removeAttribute("disabled"); btn.innerHTML = "獲取驗證碼"; wait = 60; }else{ btn.setAttribute("disabled",true); btn.innerHTML = wait + "秒後重試"; wait--; setTimeout(function(){ time(btn); },1000); } } getCode.onclick = function(){ time(this); };