<span class="mui-btn mui-btn-link" id="bindCardPay">获取验证码</span>
<button id="btn" >获取验证码</button>-
var test = { node: null, count: 60, start: function () { if (this.count > 0) { this.node.innerHTML = this.count-- + "秒后重新获取"; var _this = this; setTimeout(function () { _this.start(); }, 1000); } else { this.node.removeAttribute("disabled"); this.node.innerHTML = "重新获取"; //120秒读完,变回开始背景颜色,在这里添加。 this.count = 60; } }, //初始化 init: function (node) { this.node = node; this.node.setAttribute("disabled", true); this.start(); } }; var btn = document.getElementById("bindCardPay"); btn.onclick = function () { bindCardPay(); }
function bindCardPay(){
test.init(btn);//倒计时开始
}