倒计时器(简单的事件的注册派发)

 
  
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" >
< title > CountDown </ title >
< script type ="text/javascript" src ="../lib/jquery-1.4.2.min.js" ></ script >
< script type ="text/javascript" >
/* *
* 倒计时器: 用户可以自定义倒计时时间,时间到了,提示用户
*
*/
/* *
* 定义一个time对象
*/
var time = new Object();
/* * 定义监听函数数组 */
time.eventStack
= new Array();
/* *
* time对象增加addEvent属性
* @param {Object} eventName 事件名
*/
time.addEvent
= function (eventName){
if ( ! time.eventStack[eventName]){
time.eventStack[eventName]
= new Array();
}
}
time.addListener
= function (eventName,listener){
time.eventStack[eventName].push(listener);
}
time.dispatcher
= function (eventName){
for ( var i in time.eventStack[eventName]){
time.eventStack[eventName][i]();
}
}

time.addEvent(
' timeover ' );
time.addListener(
' timeover ' , function (){
var now = $( ' #text ' ).val();
var a = setInterval( function (){
now
-- ;
$(
' #content ' ).html(now);
if (now == 0 ){
alert(
' Time Over .... ' );
clearInterval(a);
}
},
1000 );
});
$(document).ready(
function (){
$(
' #btn ' ).click( function (){
time.dispatcher(
' timeover ' );
});
});
</ script >
</ head >
< div id ="title" > 输入你需要倒计时的时间(以秒为单位) </ div >< div id ="content" ></ div >
< input type ="text" id ="text" > < input type ="button" id ="btn" value ="sub" >
< body >
</ body >
</ html >

转载于:https://www.cnblogs.com/ifbs/archive/2011/04/20/2021895.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值