溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

js倒記時代碼開發(fā)

發(fā)布時間:2020-07-10 10:20:14 來源:網(wǎng)絡(luò) 閱讀:657 作者:771541213 欄目:web開發(fā)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" >
<title></title>

</head>
<body onload="leftTimer()">

<h3>投標倒記時:</h3>

<table>
    <tr>
        <td id="days" ></td>
        <td id="hours"></td>
        <td id="minutes"></td>
        <td id="seconds"></td>
    </tr>
</table>

<style type="text/css">
    td{ background: #1e7bb3;  padding: 0 10px;  height: 50px; line-height: 50px; font-size: 30px; color: #fff; font-weight: bold;}
</style>

</body>
</html>

<script language="javascript" type="text/javascript">

var itimer=null;

function checkTime(i){ //將0-9的數(shù)字前面加上0,例1變?yōu)?1

     if(i <1)
     {
        return "00";
     }
     else
     {
        if(i<10)
         {
             i = "0" + i;
         }
         return i;
     }

}
function c(a)
{
    console.log(a);
}

function leftTimer(year,month,day,hour,minute,second){

    var leftTime = (new Date(year,month-1,day,hour,minute,second)) - (new Date()); //計算剩余的毫秒數(shù)
      var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //計算剩余的天數(shù)
     var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //計算剩余的小時
     var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//計算剩余的分鐘
     var seconds = parseInt(leftTime / 1000 % 60, 10);//計算剩余的秒數(shù)
     var seconds11=seconds;
      days = checkTime(days);
     hours = checkTime(hours);
     minutes = checkTime(minutes);
     seconds = checkTime(seconds);

    document.getElementById("days").innerHTML = days+"天";
    document.getElementById("hours").innerHTML = hours+"小時";
    document.getElementById("minutes").innerHTML = minutes+"分";
    document.getElementById("seconds").innerHTML = seconds+"秒";

    //清除定時器任務(wù)
    if(seconds11 < 0)
    {
        clearInterval(itimer);
    }

    c(leftTime);
}

window.onload = function(){
    itimer= setInterval("leftTimer(2018,03,07,10,30,00)",1000);
}

</script>
向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI