当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 分时段切换CSS(JavaScript,ASP,PHP)

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 分时段切换CSS(JavaScript,ASP,PHP)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-13   浏览: 455 ::
收藏到网摘: n/a

一个网站能切换不同的CSS风格大家应该都了解,像众所周知的腾讯在今年改版时也增加了切换皮肤的功能。
大家可以先看一下这两个网站:http://www.katgal.com       http://www.leemunroe.com/
上面的这两个网站就是根据时间自动调整站点风格,其实这种根据时间自动调整站点风格也不是什么新鲜事了,记得好久以前也见过类似的文章或方法,只不过当时没有特别注意。

好的,下面说一下它们的实现方法,目前网上有这样两种实现方法
1)   采用服务端的代码
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';
?>
" />

2)   采用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


http://www.leemunroe.com/站点根据当时的时间自动调整其网站风格的截图







http://www.katgal.com站点根据当时的时间自动调整其网站风格的截图










原文出于:http://www.csslong.cn/article.asp?id=104