欢迎光临新华电脑职业培训-现代电脑-新东方学校网站!
网页设计中的PHP实现页面样式切换-福建百科教育网-技术支持
作者:福建百科教育 时间:2021-01-27
点击数:
收藏 分享到:
网页设计中的PHP实现页面样式切换-福建百科教育网
changStyle.php:
1 $color = $_GET["color"];
2 setcookie('color',$color,time()+31536000);
3 header("location:".$_SERVER['HTTP_REFERER']);
index.php:
1 <?php
2 if(isset($_COOKIE['color'])){
3 $color = $_COOKIE['color'];
4 //通过选择得到的当前样式
5 $style = "../webdoc/css/service/".$color."/style.css";
6 }else{
7 //页面加载后默认的样式
8 $style = "../webdoc/css/service/blue/style.css";
9 }
10 ?>
index.php中的head部分:
1 <link rel="stylesheet" type="text/css" href="<?php echo $style ?>" />
index.php中的html部分:
1 <a href="changeStyle.php?color=blue">蓝色</a>
2 <a href="changeStyle.php?color=gray">灰色</a>
3 <a href="changeStyle.php?color=red">红色</a>
4 <a href="changeStyle.php?color=green">绿色</a>