zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js倒计时详解编程语言

JS编程语言 详解 倒计时
2023-06-13 09:20:31 时间

利用setInterval制作简单的js倒计时,点击按钮将触发定时器且按钮不可用


html:

[html] 
view plain
 copy


button id= code   >

JS:

[javascript] 
view plain
 copy


 
在CODE上查看代码片
派生到我的代码片

script type= text/javascript    var i;   function getCode(){   $( #code ).attr({ disabled : disabled });   i = self.setInterval( countdown() , 1000);   }     var int = 10   function countdown() {   document.getElementById( code ).innerHTML = int +  秒后重新发送 ;   int    if(int 0){   i=window.clearInterval(i)//结束   int = 10; //重新赋值   $( #code ).removeAttr( disabled ).html( 重新获取校验码 );//将按钮可用   }   }    /script   转自blog.ytso.com/article/details/45849669