js 倒计时

来源:互联网 发布:花生壳赠送的免费域名 编辑:程序博客网 时间:2024/05/18 02:15

js 倒计时


代码如下:

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>倒计时</title></head><body><input type="button" id="eventBtn" value="点击事件"/></body><script type="text/javascript">window.onload=function(){var eventBtn = document.getElementById("eventBtn");    eventBtn.onclick = function(){       alert("事件已经被触发……");       timeUpdate.init(eventBtn, 30);    };}var timeUpdate = {   node:null,//节点   time:60,//时间   //主函数   start:function(){  if(this.time > 0){ this.node.value = this.time-- + ' 秒'; var _this = this; setTimeout(function(){ _this.start(); },1000);  }else{ this.node.removeAttribute("disabled"); this.node.value = "点击事件"; this.time = 60;  }   },   //初始化   init:function(node, timeLimit){  this.node = node;  this.time = timeLimit;  this.node.setAttribute("disabled",true);  this.start();   }};</script></html>








0 0
原创粉丝点击