内容介绍
在使用手机号注册网站的时候,需要发送短信验证码,如果不限制多长时间二次发送,那问题就大了,邪恶的用户就大量点击发送短信验证,今天分享一个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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。