ASP、PHP与javascript根据时段自动切换CSS皮肤的代码
(编辑:jimmy 日期: 2024/11/15 浏览:3 次 )
根据时间自动调整站点风格是不错的想法,这种根据时间自动调整站点风格也不是什么新鲜事,记得好久以前也见过类似的文章或方法,只不过当时没有特别注意。下面说一下它们的实现方法,目前网上有这样两种实现方法:
一、采用服务端的代码
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>
一、采用服务端的代码
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>
下一篇:css为图片设置背景图片