
正文
HTML--JS 定时刷新、时钟、倒计时
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
<html>
<head>
<title>定时刷新时间</title>
<script language="JavaScript"> //<script language="JavaScript" src="js.js">
function time(){
var now =new Date().toLocaleString();
alert(now);
} function start(){
timmerID=window.setInterval("time()",1000); //调取函数,调取频率毫秒
}
function stop(){
window.clearInterval(timmerID); //只有遇到clearInterval() 才停止
} </script>
</head>
<body>
<input type ="button" value="时间" onclick="time()"></button>
<input type ="button" value="启动" onclick="start()"></button>
<input type ="button" value="停止" onclick="stop()"></button> </body>
</html>
<html>
<head>
<title>时钟、倒计时</title>
<script language="JavaScript"> function rtime(){
var djs = document.getElementById("count").innerText;
if(djs!=0){
document.getElementById("count").innerText=djs-1;
setTimeout("rtime()",100); //调取函数,调取频率毫秒 只掉一次
}
}
function time(){
var now = new Date();
var hour = now.getHours();
var min = now.getMinutes();
var second = now.getSeconds();
var apm = "AM";
if(hour>12){
hour=hour-12;
apm = "PM";
}
if(hour<10){
hour="0"+hour;
}
if(min<10){
min="0"+min;
}
if(second<10){
second="0"+second;
}
document.form1.myclock.value = hour+":"+min+":"+second+" "+apm ;
setTimeout("time()",1000);
} </script>
</head>
<body onload="time()">
<form name="form1">
<input type="text" name="myclock">
<div id="count" >111</div>
<input type="button" value="倒计时开始" onclick="rtime()">
</form> </body>
</html>








