javascript2014-07-17 00:23:57 3281
timer,想必大家都不陌生,我们在很多地方都使用过他。比如计时,闹钟,日期包括一些javascript的动画的实现也离不开它。今天就来简单的介绍下他的用法。
这是一个显示当前时间的演示代码,间隔为1秒。
//开启timer function StartTimer(){ //定义timer的时间间隔为1000毫秒(也就是1秒) mDuration=1000; mTestTimer=setInterval("TestFunction()", mDuration); } //停止timer function StopTimer(){ clearInterval(mTestTimer); } //执行函数 function TestFunction(){ var dateTime=new Date(); document.getElementById("MainContainer").innerHTML=dateTime.getFullYear() "年" dateTime.getMonth() "月" dateTime.getDay() "日" dateTime.getHours() "时" dateTime.getMinutes() "分" dateTime.getSeconds() "秒"; }
彭亚欧个人博客原创文章,转载请注明出处
文章关键词:jsTimer htmlTimer使用 timer使用
文章固定链接:https://www.pengyaou.com/legendsz/front/codejs/NTM=.html
下一篇 SQLServer 储存过程