php设置网页颜色效果代码

2025-10-02 09:06:17

1、首先,新建两个文件:

一个:changecolor.php

代码:

<?php

if(isset($_GET["cl"])){

    $color = $_GET["cl"];

    echo "<div style='text-align:center;width:100%'>".$color."</div>";

    echo "<style>body{background-color:$color}</style>";

}

?>

一个:bgcolor.html

代码:

<!DOCTYPE HTML>

<html>

<head>

 <meta http-equiv="content-type" content="text/html" />

 <meta name="author" content="jingyan.baidu.com" /> 

 <title>背景颜色变更</title>

</head> 

<body style="text-align:center;">

<form action="changecolor.php" method="get">

<select name="cl">

<option selected="true">Red</option>

<option>Blue</option>

<option>Pink</option>

<option>Black</option>

<option>Purple</option>

</select>

<input type="submit" value="chang"/>

</form>

</body>

</html>

2、放入本地服务器,小编用的是APMServ5.2.6,启动后,在浏览器直接访问(如图)

选择一个颜色,点击chang按钮,效果出现了

php设置网页颜色效果代码

php设置网页颜色效果代码

php设置网页颜色效果代码

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢