js 倒计时
2014-09-22 16:58
190 查看
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>
相关文章推荐