Js controls instance code for displaying different css styles in different time periods

Source: Internet
Author: User

Javascript functions can be placed in a separate js file or in the

Copy codeThe Code is as follows:
Function getCSS ()
{
Datetoday = new Date ();
Timenow = datetoday. getTime ();
Datetoday. setTime (timenow );
Thehour = datetoday. getHours ();
If (thehour <12)
Display = "1.css ";
Else if (thehour> 12)
// Style table name, or you can add a path
Display = "1.css ";
Else
Display = "2.css ";
// (... If you want to add more ...)

Var css = '<';
Css + = 'link rel = "stylesheet" href = '+ display + '\/';
Css + = '> ';
Document. write (css );
}

Apply the HTML file of the style sheet

Copy codeThe Code is as follows:
<Html>
<Head>
<Title> display different prompts at different times </title>
<Script type = "text/javascript" src = "dacss. js"> </script>
</Head>
<Body>
<Script type = "text/javascript">
Window. onload = getCSS ();
</Script>

Js controls different css styles for different time periods
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.