• 2022-06-07
    编写程序,实现电子时钟自动走动的效果,并提供一个按钮控制电子时钟是否停止走动。
  • <style>div{ height:50px; line-height:50px; text-align:center; border:double #ccc; width:100px;}</style><div id="clock"></div><p><button id="btn">暂停/开始</button></p><script> window.onload = startTime; var timer = null; function startTime() { var now = new Date(); // 获取当前的时间的毫秒数 var h = now.getHours(); // 获取now的小时 (0 ~ 23) var m = now.getMinutes(); // 获取now的分钟 (0 ~ 59) var s = now.getSeconds(); // 获取now的秒数 (0 ~ 59) // 利用两位数字表示 分钟 和 秒数 m = m < 10 ? '0'+ m : m; s = s < 10 ? '0'+ s : s; document.getElementById('clock').innerHTML = h + ":" + m + ":" + s timer = setTimeout('startTime()', 500); } // 通过按钮控制时钟暂停或开始 document.getElementById('btn').onclick = function(){ if(timer){ clearTimeout(timer); timer = null; }else{ startTime(); } }</script>

    内容

    • 0

      在时钟走动这节课中,指针是怎么制作的?

    • 1

      程序题:编写代码,实现小时钟显示

    • 2

      计量原子时的时钟称为原子钟,国际上是以( )为基准

    • 3

      原子失去电子变成离子时,最先失去的一定是基态时能量最高的电子。

    • 4

      在时钟走动这节课中,按什么快捷键可以打开旋转属性?