如何使用表单和php更改html页面的背景色?
输入所选颜色后,页面应更改其背景色。应该使用html表单来完成如何使用表单和php更改html页面的背景色?,php,html,forms,Php,Html,Forms,输入所选颜色后,页面应更改其背景色。应该使用html表单来完成 <body bgcolor="<?php $_GET["color"]; ?>"> <form method="get" name="color"> Background color:<br> <input type="text" name="color"> <input type="submit" value=
<body bgcolor="<?php $_GET["color"]; ?>">
<form method="get" name="color">
Background color:<br>
<input type="text" name="color">
<input type="submit" value="submit">
</form>
</body>
您必须回显变量$\u GET[“color”]
中存储的值,如
<body bgcolor="<?php echo $_GET["color"]; ?>">
您应该使用CSS而不是HTML属性来装饰HTML呈现。此外,您还应该知道哪个组织代表更好的组织,因为它是分离语言的(=将CSS与HTML分离)
因此,要回答您的问题,您可以这样做:
<?php
if (!isset($_GET["color"]) || $_GET["color"] === '')
{
$_GET["color"] = 'pink';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<style>
body {
background-color: '<?= $_GET["color"] ?>';
}
</style>
</head>
<body>
<form method="get" name="color">
Background color:<br>
<input type="text" name="color">
<input type="submit" value="submit">
</form>
</body>
</html>
我的网站
身体{
背景色:'';
}
背景色:
<?php if(!empty($_GET['color']) {?>
<body style="background-color:'<?php echo $_GET['color'];?>">
<?php }else {?>
<body style="background-color:orange">
<?php } ?>
<form method="get" name="formcolor">
Background color:<br>
<input type="text" name="color">
<input type="submit" value="submit">
</form>
</body>
<?php
if (!isset($_GET["color"]) || $_GET["color"] === '')
{
$_GET["color"] = 'pink';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<style>
body {
background-color: '<?= $_GET["color"] ?>';
}
</style>
</head>
<body>
<form method="get" name="color">
Background color:<br>
<input type="text" name="color">
<input type="submit" value="submit">
</form>
</body>
</html>