⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clock.js

📁 这是《JavaScript学习源代码》一书的源代码
💻 JS
字号:
function tick()
{                                      
  // create a new Date object
  var now = new Date();                              
  // extract the current hours, minutes and seconds
  var hh = now.getHours();   
  var mn = now.getMinutes();   
  var ss = now.getSeconds();
  // ensure each component has two digits
  if( hh <= 9 ) hh = "0" + hh;
  if( mn <= 9 ) mn = "0" + mn; 
  if(ss <= 9 ) ss = "0" + ss; 
   
  // assign the current time string to the div
  window.document.getElementById("clock").innerHTML = hh + ": " +mn+ ": " + ss;        
  
  // set the interval before calling this function again
  window.setTimeout( "tick()", 1000 );                    
}

// start the clock
window.onload=tick;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -