// JScript 文件
function CountDown()
{
this.customDateTime=({years:0,months:0,days:0,hours:0,minutes:0,seconds:0,Ms:0});
this.timerVariable=1111;
this.countMs=0;
this.successCallBack="";
this.triggerCallBack="";}
CountDown.prototype =
{
//计时开始并返回自定义时间对象,countMs倒计时的毫秒数,successCallBack回调函数名称,触发回调triggerCallBack
timer:function(countMs,successCallBack,triggerCallBack)
{
/* alert("sss");
alert(this.timer);
alert(this.timerVariable+"\n"+triggerCallBack+"()\n"+successCallBack+"\n"+triggerCallBack);*/
this.successCallBack=successCallBack;
this.triggerCallBack=triggerCallBack;
this.countMs=countMs;
this.IsRun=true;
var THIS=this;
this.countMs=this.countMs-1000;
this.convertToDateTime(this.countMs);
eval(this.triggerCallBack+"()");
if(this.countMs<=0)
{
this.IsRun=false;
eval(successCallBack+"()");
}
function run()
{
THIS.timer(THIS.countMs,THIS.successCallBack,THIS.triggerCallBack);
}
if(this.IsRun)
{
//setTimeout无返回值
setTimeout(run(),10000));
}
},
//将时分秒转化为毫秒type:Hours/Minutes/Seconds
convertToMS:function(count,type)
{
var customMs=0;
if(count>0)
{
if(Type=="Hours")
{
customMs=count*60*60*1000;
}
else if(Type=="Minutes")
{
customMs=count*60*1000;
}
else if(Type=="Seconds")
{
customMs=count*1000;
}
}
},
//将毫秒转化为自定义时间对象输出
convertToDateTime:function(inputMs)
{
var years=0;
var months=0;
var days=0;
var hours=0;
var minutes=0;
var seconds=0;
var Ms=0;
if(inputMs>0)
{
if(inputMs>=(365*24*60*60*1000))
{
years=Math.floor(inputMs/(365*24*60*60*1000));
inputMs=inputMs-(365*24*60*60*1000)*years;
}
if(inputMs>=(30*24*60*60*1000))
{
months=Math.floor(inputMs/(30*24*60*60*1000));
inputMs=inputMs-months*(30*24*60*60*1000);
}
if(inputMs>=(24*60*60*1000))
{
days=Math.floor(inputMs/(24*60*60*1000));
inputMs=inputMs-days*(24*60*60*1000);
}
if(inputMs>=(60*60*1000))
{
hours=Math.floor(inputMs/(60*60*1000));
inputMs=inputMs-hours*(60*60*1000);
}
if(inputMs>=(60*1000))
{
minutes=Math.floor(inputMs/(60*1000));
inputMs=inputMs-minutes*(60*1000);
}
if(inputMs>=1000)
{
seconds=Math.floor(inputMs/1000);
inputMs=inputMs-seconds*1000;
}
if(inputMs>1)
{
Ms=inputMs;
}
this.customDateTime.years=years;
this.customDateTime.months=months;
this.customDateTime.days=days;
this.customDateTime.hours=hours;
this.customDateTime.minutes=minutes;
this.customDateTime.seconds=seconds;
this.customDateTime.Ms=Ms;
}
}
}
function CountDown()
{
this.customDateTime=({years:0,months:0,days:0,hours:0,minutes:0,seconds:0,Ms:0});
this.timerVariable=1111;
this.countMs=0;
this.successCallBack="";
this.triggerCallBack="";}
CountDown.prototype =
{
//计时开始并返回自定义时间对象,countMs倒计时的毫秒数,successCallBack回调函数名称,触发回调triggerCallBack
timer:function(countMs,successCallBack,triggerCallBack)
{
/* alert("sss");
alert(this.timer);
alert(this.timerVariable+"\n"+triggerCallBack+"()\n"+successCallBack+"\n"+triggerCallBack);*/
this.successCallBack=successCallBack;
this.triggerCallBack=triggerCallBack;
this.countMs=countMs;
this.IsRun=true;
var THIS=this;
this.countMs=this.countMs-1000;
this.convertToDateTime(this.countMs);
eval(this.triggerCallBack+"()");
if(this.countMs<=0)
{
this.IsRun=false;
eval(successCallBack+"()");
}
function run()
{
THIS.timer(THIS.countMs,THIS.successCallBack,THIS.triggerCallBack);
}
if(this.IsRun)
{
//setTimeout无返回值
setTimeout(run(),10000));
}
},
//将时分秒转化为毫秒type:Hours/Minutes/Seconds
convertToMS:function(count,type)
{
var customMs=0;
if(count>0)
{
if(Type=="Hours")
{
customMs=count*60*60*1000;
}
else if(Type=="Minutes")
{
customMs=count*60*1000;
}
else if(Type=="Seconds")
{
customMs=count*1000;
}
}
},
//将毫秒转化为自定义时间对象输出
convertToDateTime:function(inputMs)
{
var years=0;
var months=0;
var days=0;
var hours=0;
var minutes=0;
var seconds=0;
var Ms=0;
if(inputMs>0)
{
if(inputMs>=(365*24*60*60*1000))
{
years=Math.floor(inputMs/(365*24*60*60*1000));
inputMs=inputMs-(365*24*60*60*1000)*years;
}
if(inputMs>=(30*24*60*60*1000))
{
months=Math.floor(inputMs/(30*24*60*60*1000));
inputMs=inputMs-months*(30*24*60*60*1000);
}
if(inputMs>=(24*60*60*1000))
{
days=Math.floor(inputMs/(24*60*60*1000));
inputMs=inputMs-days*(24*60*60*1000);
}
if(inputMs>=(60*60*1000))
{
hours=Math.floor(inputMs/(60*60*1000));
inputMs=inputMs-hours*(60*60*1000);
}
if(inputMs>=(60*1000))
{
minutes=Math.floor(inputMs/(60*1000));
inputMs=inputMs-minutes*(60*1000);
}
if(inputMs>=1000)
{
seconds=Math.floor(inputMs/1000);
inputMs=inputMs-seconds*1000;
}
if(inputMs>1)
{
Ms=inputMs;
}
this.customDateTime.years=years;
this.customDateTime.months=months;
this.customDateTime.days=days;
this.customDateTime.hours=hours;
this.customDateTime.minutes=minutes;
this.customDateTime.seconds=seconds;
this.customDateTime.Ms=Ms;
}
}
}
解决方案 »
- C#.txt内容存入DataTable中
- 如何对DATAGRIDVIEW控件进行数据显示刷新?
- datagridview 如何打开自动定位到最后一行
- 关于C#WINFORM的混淆工具
- 网络通信的问题:如何获取局域网内的所有IP? 请教高手
- 有没有可能用ADO.NET把SQLServer数据库中的Stored Procedure 名称、参数 全部列出来?
- 关于JSON的反序列化问题
- 请教:如何实现按键盘Delete键删除ComboBox当前选中项?
- SourceSafe问题??
- C#中关于DataGridView刷新后,选中刷新前的选中值的问题
- xml导入至DATASET报错
- 正则表达式的写法,高手来看看
1:为什么我的setTimeout无返回值
2:我该怎么样实现这个计时器
<script type="text/javascript" >var Timer=new CountDown();
var inputMs=1000*60;
Timer.timer(inputMs,'Success','Trigger');function Trigger()
{
var MyDate=Timer.customDateTime;
var Result="";
Result+="Years:"+MyDate.years+"<br />";
Result+="Months:"+MyDate.months+"<br />";
Result+="Days:"+MyDate.days+"<br />";
Result+="Hours:"+MyDate.hours+"<br />";
Result+="Minutes"+MyDate.minutes+"<br />";
Result+="Seconds:"+MyDate.seconds+"<br />";
Result+="Ms:"+MyDate.Ms+"<br />";
document.write(Result);
}
function Success()
{
alert("Success");
return;
}
</script>
<script>
var alltime=300;
function setTime(){
if (alltime<=0){
alert("时间到!");
clearInterval(s);
}
else{
alltime--;
m=Math.floor(alltime/60);
se=Math.round(alltime-(Math.floor(alltime/60)*60));
test.innerText="剩余"+m+"分"+se+"秒";
}
}
s=setInterval("setTime()",1000)
</script> 1.计时器的范例代码
<html>
<head>
<title>计时器的范例</title>
<script language="javascript">
<!--
var CallTimeLen = "0";
var timer1 = null;function DoCallTimer()
{
var minute="0";
var second="0";
CallTimeLen = parseInt(CallTimeLen)+1;
minute = parseInt(CallTimeLen/60);
second = CallTimeLen%60;
if(minute=="0")
{
document.frmtimer.thzt.innerText ="您已通话:"+second+"秒";
}
else
{
document.frmtimer.thzt.innerText ="您已通话:"+minute+"分"+second+"秒";
}
window.timer1 = window.setTimeout("DoCallTimer()",1000);
}
function stop()
{
clearTimeout(window.timer1);
}
-->
</script>
</head>
<body>
<form name="frmtimer" action="" method="post">
<hr>
<input type="text" name="thzt" id="thzt">
<br>
<input type="button" value="开始计时" name="start" onClick="DoCallTimer()">
<input type="button" value="停止" name="stop" onClick="clearTimeout(window.timer1);">
<hr>
</form>
</body>
</html> 2.倒计时器的范例代码
<html>
<head>
<title>计时器的范例</title>
<script language="javascript">
<!--
var CallTimeLen = "0";
var begintime;
var timer = null;function DoConverseCallTimer()
{
//alert(document.frmtimer.thzt.value);
if(document.frmtimer.thzt.value == "")
alert("请输入倒计时开始的秒数!");
else
{
document.frmtimer.conversestart.disabled=true;
var minute="0";
var second="0";
begintime = parseInt(begintime)-1;
minute = parseInt(begintime/60);
second = begintime%60;
if(minute=="0")
{
document.frmtimer.thzt.innerText ="您剩余的时间为:"+second+"秒";
}
else
{
document.frmtimer.thzt.innerText ="您剩余的时间为:"+minute+"分"+second+"秒";
}
timer1 = window.setTimeout("DoConverseCallTimer()",1000);
}
}function setBegintime()
{
document.frmtimer.conversestart.disabled=false;
begintime = document.frmtimer.thzt.value;
}
-->
</script>
</head>
<body>
<form name="frmtimer" action="" method="post">
<hr>
<input type="text" name="thzt" id="thzt" onKeyup="value="/blog/value.replace(/["^\d]/g,'');setBegintime()">
<br>
<input type="button" value="开始倒计时" name="conversestart" onClick="DoConverseCallTimer()">
<input type="button" value="停止" name="stop" onClick="clearTimeout(window.timer1);">
<hr>
</form>
</body>
</html>
我用过不行
还是没返回值