jQuery教程

jQuery五一劳动节倒计时

本文主要是介绍jQuery五一劳动节倒计时,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery-3.6.0.js"></script>
    <script>
        $(function () {
                setInterval(function () {
                    var now = new Date();
                    var workerDay = new Date("2021-5-1 00:00:00");
                    var second = (workerDay.getTime() - now.getTime()) / 1000;

                    var day = parseInt(second / (60 * 60 * 24));

                    second -= day * 60 * 60 * 24;

                    var hour = parseInt(second / (60 * 60));

                    second -= hour * 60 * 60;

                    var minute = parseInt(second / 60);

                    second -= minute * 60;

                    var restTime = "距离五一劳动节还有" + day + "天"
                        + hour + "小时" + minute + "分" + parseInt(second) + "秒";

                    $("#restTime").text(restTime);

                }, 1000)
            })
    </script>
</head>
<body>
    <h2 id="restTime"></h2>
</body>
</html>

 

这篇关于jQuery五一劳动节倒计时的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!