1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <!--引入框架--> 7 <link href="resource/bootstrap/css/bootstrap.css" rel="stylesheet"> 8 <script src="resource/jQuery/jquery-1.11.3.js"></script> 9 <script src="resource/bootstrap/js/bootstrap.js"></script> 10 11 <!--引入自己的js--> 12 <script src="js/demo1.js"></script> 13 14 <style> 15 /*css选择器:class,id,标签,复合选择器*/ 16 </style> 17 </head> 18 <body> 19 <!-- <script> 20 window.onload=init; 21 setInterval('init()',1000); 22 function init() 23 { 24 var date = new Date(); 25 var year = date.getYear(); 26 var month = date.getMonth()+1; 27 if(month<10)month="0"+month; 28 var day = date.getDate(); 29 if(day<10)day="0"+day; 30 var hour = date.getHours(); 31 if(hour<10)hour="0"+hour; 32 var minute = date.getMinutes(); 33 if(minute<10)minute="0"+minute; 34 var second = date.getSeconds(); 35 if(second<10)second="0"+second; 36 var dateTime = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second; 37 document.getElementById("dateTime").value= dateTime; 38 } 39 </script> 40 <input type="text" name="dateTime" readonly> --> 41 <SCRIPT> 42 <!-- 43 document.write("<span id='time'></span>") 44 setInterval("time.innerText=new Date().toLocaleString()",1000) 45 //--> 46 </SCRIPT> 47 48 49 50 </body> 51 </html>
window.setInterval的用法与实例
window.setInterval()
功能:按照指定的周期(以毫秒计)来调用函数或计算表达式。
语法:setInterval(code,millisec)