根據時間自動調整網站風格是不錯的想法,這種根據時間自動調整網站風格也不是什麼新鮮事,記得好久以前也見過類似的文章或方法,只不過當時沒有特別注意。下面說一下它們的實現方法,目前網上有這樣兩種實現方法:
一、採用服務端的代碼
ASP版本:
<link rel="stylesheet" type="text/css" href="
<%
if hour(now)<12 then
response.write "morning.css"
elseif hour(now)<17 then
response.write "day.css"
else
response.write "night.css"
end if
%>
"/>
PHP版本:
<link rel="stylesheet" type="text/css" href="
<?php
$hour = date(”H”);
if($hour < 12)
echo ‘morning.css';
else if($hour < 17)
echo ‘day.css';
else
echo ‘night.css';
?>
" />
二、採用JavaScript代碼
<script type="text/javascript">
<!–
function getCSS(){
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour<12)
display = "morning.css";
else if (thehour<17)
display = "day.css";
else
display = "night.css";
//(…想要更多再加即可…)
var css = ‘<';
css+='link rel="stylesheet" href='+display+' \/';
css+='>';
document.write(css);
}
–>
</script>