正文 1052字数 186,050阅读

<body> <button id="btn" style="width:70px;">发送</button> </body> <script type="text/javascript"> var test = { node:null, count:60, start:function(){ //console.log(this.count); 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 = "再次发送"; this.count = 60; } }, //初始化 init:function(node){ this.node = node; this.node.setAttribute("disabled",true); this.start(); } }; var btn = document.getElementById("btn"); btn.onclick = function(){ alert("发送成功..."); test.init(btn); }; </script>
Run code
Cut to clipboard