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 οnlοad="time()">
<div id="t"></div>
</BODY>
</HTML>
setInterval&clearInterval
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/103046151