如何根据日期调用CSS
<script language="javascript">
var d=new Date();
var weekday=new Array("1","2","3","4","5","6","7");
var curday=d.getMonth()+1+"."+d.getDate();
var setday="1.28";//自定义的日期
if(curday==setday){
document.write('<link rel="stylesheet" href="/skin/skyweb/css/sky.css" type="text/css" />');
}else{
document.write('<link rel="stylesheet" href="/skin/skyweb/css/skyred.css" type="text/css" />');
}
</script>
思良:即1月28日就调用sky.css,其他时间调用skyred.css。测试能用(自己改了下),其他效果可以看原文。
下面的没测试。
原文:
<script language="javascript"> var d=new Date(); var weekday=new Array("1","2","3","4","5","6","7"); var curday=d.getMonth()+1+"."+d.getDate(); var setday="1.1";//自定义的日期 if(curday==setday){ document.write('<link rel="stylesheet" href="'+setday+'.css" type="text/css" />'); }else{ document.write('<link rel="stylesheet" href="'+weekday[d.getDay()]+'.css" type="text/css" />'); } </script>
按周:
<script language="javascript"> var d=new Date(); var weekday=new Array("1","2","3","4","5","6","7"); document.write('<link rel="stylesheet" href="'+weekday[d.getDay()]+'.css" type="text/css" />'); </script> 或者:
<link rel="stylesheet" href="1.css" type="text/css" id="mycss"/> <script type="text/javascript"> window.onload=function(){ var date=new Date(); var day=date.getDay(); var xing=new Array("1","2","3","4","5","6","7"); var cssDiv=document.getElementById("mycss"); switch(xing[day]) { case "1": cssDiv.href="1.css"; break; case "1": cssDiv.href="2.css"; break; case "2": cssDiv.href="1.css"; break; case "3": cssDiv.href="3.css"; break; case "4": cssDiv.href="4.css"; break; case "5": cssDiv.href="5.css"; break; case "6": cssDiv.href="6.css"; break; case "7": cssDiv.href="7.css"; } } </script>原文:http://zhidao.baidu.com/link?url=S16AsJsONCFAJL0DtFj_48uF-CP3aeqzlpS0dzJvw9ksC3ia104KUI5WoePWjyBVWFqUsSWD3tkjB-7FNzAVZDO4pIrDUZgf2wFd9DuI3Ly