[JavaScript]计数器(倒数)
2010-04-08 21:47
190 查看
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <mce:script type="text/javascript"><!-- ... /**//** * 计数器(倒数) * @author MoXie SysTem128@GMail.Com * * IE6,7 Firefox2.0 Opera 9.25 测试通过 **/ var timer = ...{ // 元素id elId : null, // outTime : null, // 初始文本 text : null, // 技术文本格式 countFormat : null, // 当前数 current : 0, // 获取操作对象 getEl : function()...{ return document.getElementById(this.elId); }, // 计数 counter : function()...{ this.current--; if (this.current>0)...{ this.writer(1); }else if (this.current == 0)...{ this.writer(0); this.onEnd(); } return true; }, // 显示 writer : function(isCount)...{ var el = this.getEl(); if (!isCount) ...{ el.value = this.text; }else...{ var counterText = this.countFormat.replace("$count",this.current); el.value = this.text+counterText; } }, // 起始时触发的动作 onStart : function()...{}, // 中止时触发的动作 onEnd : function()...{}, // 初始化 /**//** * elId 元素id * text 初始文本 * outTime 个数 * speed 速度 1000 = 1秒 * countFormat 计数显示格式 嵌入数字使用 $count * onStart 起始 动作 * onEnd 结束 动作 **/ init : function(elId,text,outTime,speed,countFormat,onStart,onEnd) ...{ this.elId = elId; this.text = text; this.current = outTime+1; this.countFormat = countFormat; if (typeof(onStart) == "function") ...{ this.onStart = onStart; onStart(); } if (typeof(onEnd) == "function") ...{ this.onEnd = onEnd; } window.setInterval("timer.counter()",speed); } } // 这里留为自定义 var myStart = function()...{ var el =document.getElementById("submitBtn").setAttribute("disabled",true); alert("Hello!"); } var myEnd = function()...{ document.getElementById("submitBtn").removeAttribute("disabled") alert("Goodbye!"); } // --></mce:script> <input type="submit" id="submitBtn" value="确认" /> <mce:script type="text/javascript"><!-- ... /**//** * elId 元素id * text 初始文本 * outTime 个数 * speed 速度 1000 = 1秒 * countFormat 计数显示格式 嵌入数字使用 $count * onStart 起始 动作 * onEnd 结束 动作 **/ timer.init("submitBtn","确认",2,500,"($count)",myStart,myEnd); // --></mce:script>
相关文章推荐
- JavaScript 网页中实现一个计算当年还剩多少时间的倒数计时程序
- BLOG技巧:用Javascript为你的Blog做一个计数器
- javascript 闭包计数器
- javascript 网页中实现一个计算当年还剩多少时间的倒数计时程序(转)
- javascript 闭包计数器
- 使用JavaScript实现一个倒数计时程序
- 倒数计数器-CountDownLatch
- javascript下计数器每秒自动加1
- Javascript实现计数器,定时警告和停止
- Javascript实现计数器,定时警告和停止
- javascript计数器
- 用JavaScript制作趣味计数器
- javascript实现计数器理解this作用域
- Javascript实现计数器,定时警告和停止
- javascript下计数器每秒自动加1
- JavaScript趣题:循环计数器
- JavaScript——计数器(基础)
- JavaScript特效:时间倒数
- javascript 案例:十秒钟后协议文本框下的注册按钮才能点击,时钟倒数