JavaScript method of changing skin style regularly every day


This article illustrates JavaScript’s approach to changing skin styles at regular intervals throughout the day. Share to everybody for everybody reference. The specific analysis is as follows:

This js code changes the skin by automatically changing the style sheet that the web page calls at different times of the day.

<script type="text/JavaScript">
<!--
function getStylesheet() {
   var currentTime = new Date().getHours();
   if (0 <= currentTime&&currentTime < 5) {
    document.write("<link rel='stylesheet' href='night.css' type='text/css'>");
   }
   if (5 <= currentTime&&currentTime < 11) {
    document.write("<link rel='stylesheet' href='morning.css' type='text/css'>");
   }
   if (11 <= currentTime&&currentTime < 16) {
    document.write("<link rel='stylesheet' href='day.css' type='text/css'>");
   }
   if (16 <= currentTime&&currentTime < 22) {
    document.write("<link rel='stylesheet' href='evening.css' type='text/css'>");
   }
   if (22 <= currentTime&&currentTime <= 24) {
    document.write("<link rel='stylesheet' href='night.css' type='text/css'>");
   }
}
getStylesheet();
-->
</script>
<noscript>
<link href="main.css" rel="stylesheet" type="text/css">
</noscript>

I hope this article has been helpful for your javascript programming.