ASP、PHP与javascript根据时段自动切换CSS皮肤的代码
编程学习 2021-07-05 11:30www.dzhlxh.cn编程入门
一个网站能切换不同的CSS风格大家应该都了解,像众所周知的腾讯在今年改版时也增加了切换皮肤的功能。
根据时间自动调整站点风格是不错的想法,这种根据时间自动调整站点风格也不是什么新鲜事,记得好久以前也见过类似的文章或方法,只不过当时没有特别注意。狼蚁网站SEO优化说一下它们的实现方法,目前网上有这样两种实现方法:
一、采用服务端的代码
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图片切换效果代码[不用js]
下一篇:css为图片设置背景图片