我是php的新手,所以我坚持这个基本问题。在这里,我创建了一个文本框和一个提交按钮。我想要的是,当我输入单词" red"在文本框中,它的背景将自动变为红色,但不幸的是问题是它没有产生任何影响。任何帮助都非常感谢。谢谢。
<html>
<head>
<title>
practice
</title>
<style type="text/css">
.red
{
background-color: red;
}
.blue
{
background-color: blue;
}
.yellow
{
background-color: yellow;
}
</style>
</head>
<body>
<?php
$fval = $_POST["val"];
if( isset( $_POST["colorme"] ) ) {
if($fval == "red")
{
echo S_POST['val'] = "red";
}
elseif($fval == "blue")
{
echo S_POST['val'] = "blue";
}
elseif($fval == "yellow")
{
echo S_POST['val'] = "yellow";
}
}
?>
<form method="post">
<input type="text" name="val" class="<?php echo $_POST['val'] ?>">
<input type="submit" name="colorme">
</form>
</body>
</html>
答案 0 :(得分:1)
你的例子
<html>
<head>
<title>practice</title>
<style type="text/css">
.red{background-color: red;}
.blue{background-color: blue;}
.yellow{background-color: yellow;}
</style>
</head>
<body>
<?php
$fval = isset($_POST["val"])?trim($_POST["val"]):'';
?>
<form method="post">
<input type="text" name="val" class="<?php echo $fval ?>">
<input type="submit" name="colormoko">
</form>
</body>
</html>
答案 1 :(得分:0)
为我尝试这个工作
<html>
<head>
<title>
practice
</title>
<style type="text/css">
.red
{
background-color: red;
}
.blue
{
background-color: blue;
}
.yellow
{
background-color: yellow;
}
</style>
</head>
<body>
<?php
$fval = "";
if( isset( $_POST["colormoko"] ) ) {
$fval = $_POST['val'];
if($fval == "red")
{
echo "<red>";
}
elseif($fval == "blue")
{
echo"<blue>";
}
elseif($fval == "yellow")
{
echo"<yellow>";
}
}
?>
<form method="post">
<input type="text" name="val" class="<?php echo $fval ?>">
<input type="submit" name="colormoko">
</form>
</body>
</html>
答案 2 :(得分:0)
function changeColor() {
var textBox = document.getElementById("textbox_coloring");
var color = textBox.value;
textBox.style.backgroundColor = color;
}
<!DOCTYPE html>
<html>
<head>
<title> coloring textbox </title>
<meta charset = 'utf-8' />
</head>
<body>
<form>
<input type = 'text' id = 'textbox_coloring' onkeyup='changeColor();'/>
</form>
</body>
</html>
此代码段通过插入文本值来更改textBox的样式来更改textBox的颜色。 它使用“onkeyup”javascript属性,允许在按下某个键后访问textBox。