JS controls different time periods display different CSS styles of instance code _javascript tips

Source: Internet
Author: User

JS function, can be placed in a separate JS file can also be placed in the current page

Copy Code code 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)
The name of the style sheet, or you can add the path
display = "1.css";
Else
display = "2.css";
(... Want to add more can be ... )

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

HTML file to which the style sheet is applied

Copy Code code as follows:

<title> display different cue messages at different times </title>
<script type= "Text/javascript" src= "Dacss.js" ></script>
<body>
<script type= "Text/javascript" >
Window.onload=getcss ();
</script>

JS controls different time periods to display different CSS styles
</body>

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.