<!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 src="../jquery-1.11.2.min.js"></script> <style type="text/css"> *{ margin:0px auto; padding:0px} #djs{ 300px; height:100px} #fen{ float:left; 100px; height:100px; text-align:center; line-height:100px; vertical-align:middle; font-size:36px; font-weight:bold; font-family:"微软雅黑"; color:#9C9} #miao{ float:left; 100px; height:100px; text-align:center; line-height:100px; vertical-align:middle; font-size:36px; font-weight:bold; font-family:"微软雅黑"; color:#9C9} #zz{ float:left; 100px; height:100px; text-align:center; line-height:100px; vertical-align:middle; font-size:36px; font-weight:bold; font-family:"微软雅黑"; color:#9C9} </style> </head> <body> <?php session_start(); //设置倒计时时间 $attr=array(); if(empty($_SESSION["djs"])) { $attr=array("fen"=>1,"miao"=>00); $_SESSION["djs"]=$attr; } else { $attr=$_SESSION["djs"]; } //开始倒计时 用JS控制 ?> <div id="djs"> <div id="fen"><?php echo $attr["fen"]; ?></div> <div id="zz">:</div> <div id="miao"><?php echo $attr["miao"]; ?></div> </div> </body> <script type="text/javascript"> $(document).ready(function(e) { window.setInterval("ShowTime()",1000);//间隔执行 }); function ShowTime() { $.ajax({ url:"djschuli.php", dataType:"TEXT", success: function(data){ if(data.trim()=="OVER") { $("#djs").text("倒计时结束"); } else { var lie=data.trim().split("|"); $("#fen").text(lie[0]); $("#miao").text(lie[1]); } } }); } </script> </html>
<?php session_start(); $attr=$_SESSION["djs"]; $fen=$attr["fen"]; $miao=$attr["miao"]; if($fen==0 && $miao==0) { echo"OVER"; exit(); } if($miao==0) { $attr["miao"]=59; $attr["fen"]=$attr["fen"]-1; } else { $attr["miao"]=$attr["miao"]-1; } $_SESSION["djs"]=$attr; echo "{$attr['fen']}|{$attr['miao']}";