JavaScript Timing 事件及两种时钟写法(2)

<!DOCTYPE html>
<html>
<body>
 
<button>试一试</button>
 
<p>点击“试一试”。我将在两秒,四秒和六秒过后显示。</p>
 
<script>
function timedText() {
  setTimeout(myTimeout1, 2000)
  setTimeout(myTimeout2, 4000)
  setTimeout(myTimeout3, 6000)
}
function myTimeout1() {
  document.getElementById("demo").innerHTML = "2 秒";
}
function myTimeout2() {
  document.getElementById("demo").innerHTML = "4 秒";
}
function myTimeout3() {
  document.getElementById("demo").innerHTML = "6 秒";
}
</script>
 
</body>
</html>

由计时时间创建的时钟

<!DOCTYPE html>
<html>
<head>
<script>
function startTime() {
  var today = new Date();
  var h = today.getHours();
  var m = today.getMinutes();
  var s = today.getSeconds();
  m = checkTime(m);
  s = checkTime(s);
  document.getElementById('txt').innerHTML =
  h + ":" + m + ":" + s;
  var t = setTimeout(startTime, 500);
}
function checkTime(i) {
  if (i < 10) {i = "0" + i};  // 在数字 < 10 之前加零
  return i;
}
</script>
</head>
 
<body>
 
<div></div>
 
</body>
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b6e0183123a4f7338d4054387f08cde0.html