欢迎来到Cecilia陈的博客

孤独,是人一生最好的修行。

[07--DOM] 当前时间显示

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取当前时间</title>
</head>
<body>
    <input type="text" id="get_date">
    <input type="button" id="start" value="开始">
    <input type="button" id="stop" value="暂停">

    <script>
        var textEle=document.getElementById("get_date");
        var start=document.getElementById("start");
        var stop=document.getElementById("stop");
        var t;

        function f() {
            var date_obj=new Date();
            var date=date_obj.toLocaleString();
            textEle.value=date;
        }
        f();
        start.onclick=function f1() {
            if (t===undefined){
                t=setInterval(f,1000);
            }
        };
        stop.onclick=function f2() {
            clearInterval(t);
            t=undefined;
        };



    </script>
</body>
</html>
posted @ 2019-10-16 23:54  Cecilia陈  阅读(174)  评论(0编辑  收藏  举报