Js controls the instance code that displays different CSS styles for different time periods

  • 2020-03-26 23:05:48
  • OfStack

Js functions can be placed in a separate js file or on the current page < Head> Within the tag


function getCSS()
{
        datetoday = new Date();
        timenow=datetoday.getTime();
        datetoday.setTime(timenow);
        thehour = datetoday.getHours();
        if (thehour<12)
            display = "1.css";
        else if (thehour>12)
            //The name of the style sheet, or you can add the path
            display = "1.css";
        else
            display = "2.css";
        //(... Just add more...)

        var css = '<';
        css+='link rel="stylesheet" href='+display+' /';
        css+='>';
        document.write(css);
}

Apply the HTML file to the stylesheet


<html>
<head>
<title> Displays different prompt messages at different times </title>
<script type="text/javascript" src="dacss.js"></script>
</head>
<body>
<script type="text/javascript">
window.onload=getCSS();
</script>
js Control different time periods to display different css style 
</body>
</html>


Related articles: