/
changeBackgroundcolor.php
64 lines (63 loc) · 1.75 KB
/
changeBackgroundcolor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
$bgcolor = $_GET['bgcolor'];
$color = $bgcolor ?? 'transparent';
$red = $orange = $yellow = $green = $cyan = $blue = $purple = '';
switch ($color) {
case 'red':
$red = 'selected';
break;
case 'orange':
$orange = 'selected';
break;
case 'yellow':
$yellow = 'selected';
break;
case 'green':
$green = 'selected';
break;
case 'cyan':
$cyan = 'selected';
break;
case 'blue':
$blue = 'selected';
break;
case 'purple':
$purple = 'selected';
break;
case 'transparent':
break;
default:
$bgcolor = 'transparent';
echo "<script>alert('该颜色不在选取范围内');</script>";
}
?>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>demo</title>
<style>
html {
background-color: <?=$bgcolor?>;
}
</style>
</head>
<body>
<form action="">
<select name="bgcolor" id="">
<option value="default">默认</option>
<option value="red" <?=$red?> >红</option>
<option value="orange" <?=$orange?> >橙</option>
<option value="yellow" <?=$yellow?> >黄</option>
<option value="green" <?=$green?> >绿</option>
<option value="cyan" <?=$cyan?> >青</option>
<option value="blue" <?=$blue?> >蓝</option>
<option value="purple" <?=$purple?> >紫</option>
</select>
<input type="submit" value="确认更改">
</form>
</body>
</html>