您的位置:首页 > Web前端 > JavaScript

[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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: