Home  >  Article  >  Web Front-end  >  如何根据时间动态加载不同的css文件?_html/css_WEB-ITnose

如何根据时间动态加载不同的css文件?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:24:181162browse

根据时间,白天加载白天用的CSS文件,晚上加载晚上用的CSS文件。

如何实现?


回复讨论(解决方案)

如果是服务器端
判断时间,然后
" rel="stylesheet" type="text/css" />
就可以了

如果采用js
你可以


window.onload=function(){
var d = new Date().getHours();
if(d>8 && d   document.getElementById("css").setAttribute("href","day.css")
}else{
document.getElementById("css").setAttribute("href","night.css")
}
}

或者
var c = "night.css"
if(d>8 && d  c="day.css"
}
document.write('')

最好还是服务器端判断。
如果是php的话,可以用apache rewrite url,把一个style.php文件改写为style.css
然后输出格式可以像这样 style.css?date=1380644282

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn