我对css有点问题。 我必须创建一个带有表单的页面,您可以通过单选按钮和提交按钮设置背景颜色。 但是我怎么能真正改变php中的css background-color?
<?php
if (isset($_POST['set'])) {
$color = $_POST['color'];
} else {
$color = "";
}
?>
<form method="post" action="">
<input type="radio" name="color" value="Red"
<?php if($color == "Red") { echo "checked='checked'"; } ?>>Red
<input type="radio" name="color" value="Green"
<?php if($color == "Green") { echo "checked='checked'"; } ?>>Green
<input type="radio" name="color" value="Blue"
<?php if ($color == "Blue") { echo "checked='checked'"; } ?>>Blue
<input type="radio" name="kleur" value="Pink"
<?php if ($color == "Pink") { echo "checked='checked'"; } ?>>Pink
<br>
<br>
<input type="submit" name="set" value="SET">
</form>
答案 0 :(得分:-1)
将body css用于body标记
<?php
if (isset($_POST['set'])) {
$color = $_POST['color'];
} else {
$color = "";
}
?>
<html>
<body <?php echo !empty($color) ? 'style="background:'.$color.'"' : ''; ?>>
<form method="post" action="">
<input type="radio" name="color" value="Red"
<?php if($color == "Red") { echo "checked='checked'"; } ?>>Red
<input type="radio" name="color" value="Green"
<?php if($color == "Green") { echo "checked='checked'"; } ?>>Green
<input type="radio" name="color" value="Blue"
<?php if ($color == "Blue") { echo "checked='checked'"; } ?>>Blue
<input type="radio" name="kleur" value="Pink"
<?php if ($color == "Pink") { echo "checked='checked'"; } ?>>Pink
<br>
<br>
<input type="submit" name="set" value="SET">
</form>
</body>