天天看点

jquery 倒计时显示

<!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=gbk" />
<title>鍊掕鏃舵祴璇?lt;/title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script>
  function lxfEndtime(){
          $(".lxftime").each(function(){
                var lxfday=$(this).attr("lxfday");//鐢ㄦ潵鍒ゆ柇鏄惁鏄剧ず澶╂暟鐨勫彉閲?                var endtime = new Date($(this).attr("endtime")).getTime();//鍙栫粨鏉熸棩鏈?姣鍊?
                var nowtime = new Date().getTime();        //浠婂ぉ鐨勬棩鏈?姣鍊?
                var youtime = endtime-nowtime;//杩樻湁澶氫箙(姣鍊?
                var seconds = youtime/1000;
                var minutes = Math.floor(seconds/60);
                var hours = Math.floor(minutes/60);
                var days = Math.floor(hours/24);
                var CDay= days ;
                var CHour= hours % 24;
                var CMinute= minutes % 60;
                var CSecond= Math.floor(seconds%60);//"%"鏄彇浣欒繍绠楋紝鍙互鐞嗚В涓?0杩涗竴鍚庡彇浣欐暟锛岀劧鍚庡彧瑕佷綑鏁般€?                if(endtime<=nowtime){
                        $(this).html("宸茶繃鏈?)//濡傛灉缁撴潫鏃ユ湡灏忎簬褰撳墠鏃ユ湡灏辨彁绀鸿繃鏈熷暒
                  }else{
                      if($(this).attr("lxfday")=="no"){
							$(this).html("<i>鍓╀綑鏃堕棿锛?lt;/i><span>"+CHour+"</span>鏃?lt;span>"+CMinute+"</span>鍒?lt;span>"+CSecond+"</span>绉?);   //娌℃湁澶╂暟鐨?                        }else{
							$(this).html("<i>鍓╀綑鏃堕棿锛?lt;/i><span>"+days+"</span><em>澶?lt;/em><span>"+CHour+"</span><em>鏃?lt;/em><span>"+CMinute+"</span><em>鍒?lt;/em><span>"+CSecond+"</span><em>绉?lt;/em>"); //杈撳嚭鏈夊ぉ鏁扮殑鏁版嵁
                         }
                 }
          });
   setTimeout("lxfEndtime()",1000);
  };
$(function(){
      lxfEndtime();
   });
</script>
<style type="text/css">
<!--
*{
font-style: normal;
font-weight: normal;
}
.haveday {
  padding: 20px;
  border: 1px dashed #000;
  margin-right: auto;
  margin-left: auto;
  width: 300px;
}
-->
</style>
</head>
<body>
<div class="haveday">
<h1>鍚湁澶╂暟鐨勫€掕鏃?lt;/h1>
<div class="lxftime" endtime="11/15/2011 17:24:0"></div>
<div class="lxftime" endtime="11/8/2011 3:3:20"></div>
<div class="lxftime" endtime="9/6/2015 6:1:0"></div>
<div class="lxftime" endtime="2016/6/6 9:3:5"></div>
</div>
<p></p>
<div class="haveday">
<h1>娌℃湁澶╂暟鐨勫€掕鏃?lt;/h1>
<div class="lxftime" endtime="11/15/2011 17:24:0" lxfday="no"></div>
<div class="lxftime" endtime="11/8/2011 3:3:20" lxfday="no"></div>
<div class="lxftime" endtime="9/6/2015 6:1:0" lxfday="no"></div>
<div class="lxftime" endtime="6/6/2016 9:3:5" lxfday="no"></div>
</div>
</body>
</html>
           

继续阅读