用JavaScript function countdown(y,m,d){ var today = new Date(); var todayy = today.getYear(); todayy = (todayy < 1000)?todayy += 1900 : todayy; var todaym = today.getMonth(); var todayd = today.getDate(); var todayh = today.getHours(); var todaymin = today.getMinutes(); var todaysec = today.getSeconds(); var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec; var futurestring=montharray[m-1]+" "+d+", "+y; dd=Date.parse(futurestring)-Date.parse(todaystring); dday=Math.floor(dd/(60*60*1000*24)*1); dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1); dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1); dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1); var final = dday + "days,<br/> "+ dhour+"hours<br/>"+dmin+"minutes<br/>" +dsec+"seconds <br/>left until the DoomDay"; document.getElementById('holder2').innerHTML = final; } </script></head><body onload = "countdown(2012,12,20);setInterval('countdown(2012,12,20)',1000);"> <h3> a doomday countdown for every human beings~</h3> <div id="holder"> </div> <div id="box"> <div id="holder2"> </div> </body> </html>辛苦帮楼组写的 可以给分了
function fun(){
if(条件){
//操作1
}else{
//操作2
}
setInterval("fun()", 1000);//setTimeout(); 1000为一秒
}
fun();
以上是js,如果是php的话就用
while(1){
if(条件){
//操作1
}else{
//操作2
}
sleep(1)//睡眠一秒
}
/**************************************
**功能:PHP实时倒计时
**创建日期:2009-2-26
**作者:潘继强 <[email protected]>
**
***************************************/
//php的时间是以秒算。js的时间以毫秒算date_default_timezone_set("Asia/Hong_Kong");//地区//配置每天的活动时间段
$nowtime = time();
$starttimestr = date("H:i:s",$nowtime);
$endtimestr = date("H:i:s",$nowtime+3600);
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
if ($nowtime<$starttime){
die("活动还没开始,活动时间是:{$starttimestr}至{$endtimestr}");
}
$lefttime = $endtime-$nowtime; //实际剩下的时间(秒)
?>
<!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=gb2312" />
<title>PHP实时倒计时!</title>
<script language="JavaScript">
<!-- //
var runtimes = 0;
function GetRTime(){
var nMS = <?=$lefttime?>*1000-runtimes*1000;
var nH=Math.floor(nMS/(1000*60*60))%24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS;
if(nMS>5*59*1000&&nMS<=5*60*1000)
{
alert("还有最后五分钟!");
}
runtimes++;
setTimeout("GetRTime()",1000);
}
window.onload=GetRTime;
// -->
</script>
</head>
<body>
<h3><strong id="RemainH">XX</strong>小时<strong id="RemainM"></strong>分钟<strong id="RemainS"></strong>秒</h3>
</body>
</html>
var today = new Date();
var todayy = today.getYear();
todayy = (todayy < 1000)?todayy += 1900 : todayy;
var todaym = today.getMonth();
var todayd = today.getDate();
var todayh = today.getHours();
var todaymin = today.getMinutes();
var todaysec = today.getSeconds();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
var futurestring=montharray[m-1]+" "+d+", "+y;
dd=Date.parse(futurestring)-Date.parse(todaystring);
dday=Math.floor(dd/(60*60*1000*24)*1);
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
var final = dday + "days,<br/> "+ dhour+"hours<br/>"+dmin+"minutes<br/>" +dsec+"seconds <br/>left until the DoomDay";
document.getElementById('holder2').innerHTML = final;
}
</script></head><body onload = "countdown(2012,12,20);setInterval('countdown(2012,12,20)',1000);">
<h3> a doomday countdown for every human beings~</h3>
<div id="holder">
</div>
<div id="box">
<div id="holder2">
</div>
</body>
</html>辛苦帮楼组写的 可以给分了
<div style='width:400;height:30px;line-height:30px;background-color:#EFFDFE;border:1px dotted #D7F1B4;text-align:center;font-size:16px;color:#FF3300;display:none' id='test'>
页面将在10秒钟后自动调转
</div>
<INPUT TYPE="button" value='点击试试' onclick="test()">
<script>
var alltime = 10;
function setTime(){
if (alltime<=0){
location.href='http://www.baidu.com' ;
clearInterval(tem);
}else{
alltime--;
document.getElementById("test").innerHTML = "页面将在0"+alltime+"秒钟后自动调转";
}
}function test()
{
showText()
tem = setInterval("setTime()",1000)
}function showText()
{
document.getElementById("test").style.display='';
}
</script>
我正在使用《Csdn收音机》第一时间获取最新动态!