php 时间倒计时
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<!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> <style type="text/css"> *{ margin:0px auto; padding:0px} #djs{ width:300px; height:100px;} #fen{ float:left; width:150px; height:100px; text-align:center; line-height:100px; vertical-align:middle; font-size:36px; font-weight:bold; font-family:微软雅黑; color:#60F} #miao{ float:left; width:150px; height:100px; text-align:center; line-height:100px; vertical-align:middle; font-size:36px; font-weight:bold; font-family:微软雅黑; color:#F00} </style> <script src="jquery-1.11.2.min.js"></script> </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="miao"><?php echo $attr["miao"]; ?></div> </div> </body> <script type="text/javascript"> $(document).ready(function(e) { window.setInterval("showtime()",1000); }); function showtime() { $.ajax({ url:"huihuachuli3.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>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?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']}";