ASP、PHP与javascript根据时段自动切换CSS皮肤的代码
根据时间自动调整站点风格是不错的想法,这种根据时间自动调整站点风格也不是什么新鲜事,记得好久以前也见过类似的文章或方法,只不过当时没有特别注意。下面说一下它们的实现方法,目前网上有这样两种实现方法:
一、采用服务端的代码
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">
<!C
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);
}
C>
</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">
<!C
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);
}
C>
</script>
相关推荐
qiupu 2020-11-04
多读书读好书 2020-11-03
RedCode 2020-10-28
jiedinghui 2020-10-25
Ladyseven 2020-10-22
hellowzm 2020-10-12
zuncle 2020-09-28
Ladyseven 2020-09-11
jiedinghui 2020-09-07
xiaohuli 2020-09-02
葉無聞 2020-09-01
impress 2020-08-26
ThikHome 2020-08-24
nicepainkiller 2020-08-20
hellowzm 2020-08-18