javascript当中时间控制setTimeout和setInterval的用法

9.时间控制setTimeout和setInterval


马克-to-win:下个例子说明每秒刷新时间如何实现。(利用setTimeout方法):
setTimeout和setInterval的区别是:setTimeout只执行1次,而setInterval可以无限执行。

例 1.9.1(setTimeoutIEFF.html)



<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<SCRIPT LANGUAGE="JavaScript">
<!--
function time()
{
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth()+1;
var d = now.getDate();
var x = now.getDay();
var hour = now.getHours();
var day =new Array("日","一","二","三","四","五","六");
var xingqi = day[x];
var mi =now.getMinutes();
var s = now.getSeconds();
var t =document.getElementById("t");
t.innerHTML="今天是"+y+"年"+m+"月"+d+"日"+"星期"+xingqi+","+hour+":"+mi+":"+s;
setTimeout("time()",1000);
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="time()">
<div id="t"></div>
</BODY>
</HTML>
更多参考原文地址:http://www.mark-to-win.com/index.html?content=Javascript/jsUrl.html&chapter=Javascript/js5_web.html#javascriptconfirm

猜你喜欢

转载自blog.csdn.net/mark_to_win/article/details/88665658