标签:javascript function minutes 定时器 seconds
(1)系统时间向后走10秒即停止
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script> var num=0; var time; function loadDate(){ var d=new Date(); var year=d.getYear(); var month=d.getMonth()+1; var day=d.getDay()+1; var hours=d.getHours(); var minutes=d.getMinutes(); var seconds=d.getSeconds(); var t=year+"/"+month+"/"+day+" "+hours+":"+minutes+":"+seconds; var sp=document.getElementById("date"); sp.innerText=t; num++; if(num==10){ clearTimeout(time); } } time=setInterval(loadDate,1000); </script> </head> <body onload="loadDate()"> <span id="date"></span> </body> </html>
(2)倒计时
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script> var timmerID = null; function time() { var time = document.getElementById("now"); var left = document.getElementById("left"); time.value=parseInt(time.value)+1; left.value = parseInt(left.value)-1; if(left.value==0){ mystop(); alert("时间已到!"); } } function mystart() { var left = document.getElementById("left"); left.value="10"; timmerID = window.setInterval("time()", 1000); } function mystop() { window.clearInterval(timmerID); } </script> </head> <body> 时间起点:<input type="text" name="now" id="now" value="0"/><input type="button" value="开始" onclick="mystart();"><br> 剩余时间:<input type="text" name="left" id="left" value="10" disabled="disabled"/>秒<br> </body> </html>
标签:javascript function minutes 定时器 seconds
原文地址:http://11302790.blog.51cto.com/11292790/1771083