网页版时钟----简单版


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>时钟title>
    <style>
        div{
            font-size: 60px;
            text-align: center;
            color: pink;
        }
        main{
            width: 600px; 
            height: 600px;
            border: 5px solid black;
            margin: 0% auto;
            /*画圆*/
            /*border-radius: :300px;*/
            border-radius: 50%;
            /*径向渐变*/
            background-image: radial-gradient(circle,violet,yellow,green,red);

        }
        section{
            width: 500px;
            height: 200px;
            border: 1px solid black;
            margin: 200px auto;
            background-color: blue;
        }
    style>
head>
<body>
    <main>
        <section>
            <div id="date">div>
            <div id="time">div>
        section>
    main>
    <script>
        function showTime(){
            var time =new Date();
            var year = time.getUTCFullYear();
            var mouth = time.getUTCMonth()+1;
            var date = time.getUTCDate();
            var day = time.getUTCDay();
            var hour = time.getHours();
            var minute = time.getMinutes();
            var second = time.getSeconds();
            /*getElementById通过ID值获取html对应标签元素*/
            /*innerHTML将一段字符串嵌入标签元素*/
            document.getElementById('date').innerHTML= year + '/' + mouth + '/' + date + ' 星期' + day ; 
            document.getElementById('time').innerHTML= hour + ':' + minute + ':' + second;
        }
        showTime();
        setInterval(showTime,1000);
    script>
body>
html>

网页版时钟----简单版_第1张图片

你可能感兴趣的:(html5)