为什么我的JavaScript时钟由于某些原因无法正常工作

我是新来的

我只是在YouTube上看到了

<html>
C:\Users\Alul\YaldexTemp$$$6.htm
        <script src="Documents/Tes/Untitled3.js"></script>
        <link rel="stylesheet" href="Documents/Tes/Untitled1.css">
        <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@500&family=Roboto:wght@100&display=swap" rel="stylesheet">        
    </head>
    <body onload="realtimeClock">
        <div class="main-container">
            <h1>Haiii!!!</h1>
            <div id="clock"></div>
            <img class="img-background" src="Documents/Tes/rsz_line_139121738639491.jpg"
        </div>
    </body>
</html>
function realtimeClock() {

    var rtClock = new Date();

    var hours = rtClock.getHours();
    var minutes = rtClock.getMinutes();
    var seconds = rtClock.getSeconds();



    var amPm = ( hours < 12 ) ? "AM" : "PM";


    hours = (hours > 12) ? hours - 12 : hours;



    hours = ("0" + hours).slice(-2);
    minutes = ("0" + minutes).slice(-2);
    seconds = ("0" + seconds).slice(-2);


    document.getElementById('clock').innerHTML =
        hours + " : " + minutes + " : " + seconds + " " + amPm;
    var t = setTimeout(realtimeClock, 500);

}
评论