zoukankan      html  css  js  c++  java
  • jQuery实现倒计时

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="UTF-8">
     5 <script src="jquery-3.1.1.min.js"></script>
     6 <title></title>
     7 <style>
     8 .clock{width:200px;height:100px;margin:200px auto;}
     9 .hour,.min,.sec{width:40px;height:30px;font-size:20px;line-height:30px;display:inline-block;text-align: center;background:#572019;color:#FFFFFF;}
    10 span:nth-child(2),span:nth-child(4){font-size:20px;}
    11 </style>
    12 <script>
    13 $(function(){
    14 function getRTime(){
    15 var dateFinal=new Date("2018/07/31 14:00:00");   //截止时间
    16 var dateNow=new Date();     //获得系统当前时间
    17 var t=dateFinal.getTime()-dateNow.getTime();    //获取差值,单位毫秒
    18 var h=(Math.floor(t/1000/60/60%24));
    19 var m=(Math.floor(t/1000/60%60));
    20 var s=(Math.floor(t/1000%60));
    21 $(".hour").text(toDouble(h));
    22 $(".min").text(toDouble(m));
    23 $(".sec").text(toDouble(s));
    24 }
    25 function toDouble(num){
    26 if(num<10){
    27 return "0"+num;
    28 }else{
    29 return ""+num;
    30 }
    31 }
    32 setInterval(getRTime,1000);
    33 })
    34 </script>
    35 <head>
    36 <body>
    37 <div class="clock">
    38 <span class="hour">00</span>
    39 <span>:</span>
    40 <span class="min">00</span>
    41 <span>:</span>
    42 
  • 相关阅读:
    java保留字
    12个不可不知的Sublime Text应用技巧和诀窍
    人生准则
    基于Android 的蓝牙A2DP 功能的实现
    蓝牙协议栈详解
    我的2015计划
    今日学习
    滤波器介绍
    STLINK V2安装使用详解
    javascript闭包
  • 原文地址:https://www.cnblogs.com/endlessmy/p/8394954.html
Copyright © 2011-2022 走看看