日期:2010-01-26  浏览次数:20830 次

一、采用服务端的代码

  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>

  考虑到客户端可能不支持或者禁止JavaScript,你需要设置一种默认的CSS