首页 > Web开发 > 详细

js实现60s倒计时效果用于获取短信验证码使用

时间:2019-08-24 00:27:56      阅读:185      评论:0      收藏:0      [点我收藏+]

有时候我们需要通过点击按钮向用户发送短信,需要一个计时效果。

 <button id="msg" type="button" style="width:120px; height:30px" >获取短信验证</button>
       <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
	 var count=60,timer=null;
     $("#msg").click(function()
	 {    
          /*防止用户重复点击按钮*/
	   if(timer==null){
	   timer=setInterval(function(){count--;$("#msg").text(count+"秒后获取验证码");
if(count<=0){clearInterval(timer);$("#msg").text("点击获取验证码");timer=null;}},1000); } }); </script>

  

显示效果:

技术分享图片

js实现60s倒计时效果用于获取短信验证码使用

原文:https://www.cnblogs.com/fogwang/p/11403154.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!