zoukankan      html  css  js  c++  java
  • HTML--JS 定时刷新、时钟、倒计时

     1 <html>
     2     <head>
     3         <title>定时刷新时间</title>
     4         <script language="JavaScript">  //<script language="JavaScript" src="js.js">
     5             function time(){
     6                 var now =new Date().toLocaleString();
     7                 alert(now);
     8             }
     9             
    10             function start(){
    11                 timmerID=window.setInterval("time()",1000);  //调取函数,调取频率毫秒
    12             }
    13             function stop(){
    14                 window.clearInterval(timmerID);  //只有遇到clearInterval() 才停止
    15             }
    16             
    17         </script>
    18     </head>
    19     <body>
    20         <input type ="button" value="时间" onclick="time()"></button>
    21         <input type ="button" value="启动" onclick="start()"></button>
    22         <input type ="button" value="停止" onclick="stop()"></button>
    23     
    24     
    25     </body>
    26 </html>


     1 <html>
     2     <head>
     3         <title>时钟、倒计时</title>
     4         <script language="JavaScript"> 
     5             
     6             function rtime(){
     7                 var djs = document.getElementById("count").innerText;
     8                 if(djs!=0){
     9                     document.getElementById("count").innerText=djs-1;
    10                     setTimeout("rtime()",100); //调取函数,调取频率毫秒 只掉一次
    11                 }
    12             }
    13             function time(){
    14                 var now = new Date();
    15                 var hour = now.getHours();
    16                 var min = now.getMinutes();
    17                 var second = now.getSeconds();
    18                 var apm = "AM";
    19                 if(hour>12){
    20                     hour=hour-12;
    21                     apm = "PM";
    22                 }
    23                 if(hour<10){
    24                     hour="0"+hour;
    25                 }
    26                 if(min<10){
    27                     min="0"+min;
    28                 }
    29                 if(second<10){
    30                     second="0"+second;
    31                 }
    32                 document.form1.myclock.value = hour+":"+min+":"+second+"  "+apm ;
    33                 setTimeout("time()",1000);
    34             }
    35             
    36         </script>
    37     </head>
    38     <body onload="time()">
    39         <form name="form1">
    40             <input type="text" name="myclock">
    41             <div id="count" >111</div>
    42             <input type="button" value="倒计时开始" onclick="rtime()">
    43         </form>
    44         
    45     </body>
    46 </html>
    
    
    
     
  • 相关阅读:
    1094. Car Pooling
    121. Best Time to Buy and Sell Stock
    58. Length of Last Word
    510. Inorder Successor in BST II
    198. House Robber
    57. Insert Interval
    15. 3Sum java solutions
    79. Word Search java solutions
    80. Remove Duplicates from Sorted Array II java solutions
    34. Search for a Range java solutions
  • 原文地址:https://www.cnblogs.com/liuyangv/p/7979262.html
Copyright © 2011-2022 走看看