jquery编写网页时钟效果

版权声明:转载请指明出处 https://blog.csdn.net/weixin_42321963/article/details/81915182
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div {
            width: 100px;
            height: 50px;
            background-color: red;
        }
    </style>
    <script type="text/javascript" src="jquery-3.3.1.js"></script>
    <script type="text/javascript">
        $("document").ready(function () {
            $("button").click(function () {
                setInterval(function () {
                    var mytime = new Date();
                    var y = mytime.getFullYear();
                    var m = mytime.getMonth();
                    var d = mytime.getDate();
                    var h = mytime.getHours();
                    var mm = mytime.getMinutes();
                    var s = mytime.getSeconds();
                    var time = y + "-" + m + "-" + d + "- " + h + ":" + mm + ":" + s;
                    $("p").html(time);
                }, 1000);
            });
        });
    </script>
</head>
<body>
<button type="button">点击显示时钟效果</button>
<p></p>
</body>
</html>

结果如下:

猜你喜欢

转载自blog.csdn.net/weixin_42321963/article/details/81915182
今日推荐