倒计时

<!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 type="text/javascript" src="jquery-1.11.2.min.js"></script>

<style type="text/css">

.djs{width: 250px;height: 100px;top: 120px;left: 180px;position: absolute;}

    #fen{float: left;font-family: 黑体;
        color: #92ff98;font-size: 40px;left: 180px;position: relative;}


#miao{float: left;font-family: 黑体;
    color: #ff9de0;font-size: 40px;left: 200px;position: relative;}

</style>
</head>

<body>
<?php
session_start();
//设置倒计时时间
    $attr=array();
    if(empty($_SESSION["djs"]))
    {
        $attr=array("fen"=>15,"miao"=>00);
        $_SESSION["djs"]=$attr;

    }
else
{
    $attr=$_SESSION["djs"];
}


//开始倒计时
//用js控制



?>
<div class="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()",30);

    });


    function showtime()
    {
        $.ajax({
            url:"0714djschuli.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 and $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']}";

  

 

posted @ 2016-07-14 15:03  庞某人  阅读(118)  评论(0编辑  收藏  举报