内容介绍
在使用手机号注册网站的时候,需要发送短信验证码,如果不限制多长时间二次发送,那问题就大了,邪恶的用户就大量点击发送短信验证,今天分享一个js短信60秒倒计时效果,希望对大家学习有所帮助。
<!DOCTYPE html> <html> <head> <Meta charset="utf-8"> <Meta name="keywords" content="" /> <Meta name="description" content="" /> <Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <Meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <Meta name="format-detection" content="telephone=no, email=no"/> <title>js短信60秒倒计时_chenxinming</title> </head> <body> <div class="container-fluid pc"> <section> <button id="btn" style="width:100px;">发送</button> </section> </div><!-- container-fluid --> <script type="text/javascript"> var timeCountDown= { 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("发送成功..."); timeCountDown.init(btn); }; </script> </body> </html>