我有两个使用框架向用户显示的 PHP 文件。 (以下是两个文件中的一小部分代码)
第一个 PHP 文件 - q11.php
echo "<form action = 'q21.php' method = 'post' id = 'sub1'>";
echo "<br><input type = 'submit' name = 'ans' value = 'a'>";
echo "<br><input type = 'submit' name = 'ans' value = 'b'>";
echo "<br><input type = 'submit' name = 'ans' value = 'c'>";
echo "<br><input type = 'submit' name = 'ans' value = 'd'>";
echo "</form>";
第二个 PHP 文件 - status.php
echo "<h4 id = 'q1'>Question 1";
现在,当用户单击属于第一个 PHP 文件 (q11.php) 的任何提交按钮时,我想更改第二个 PHP 文件 (status.php) 中 h4 元素的颜色。
在此先感谢您的指导和帮助。
最佳答案
首页
<form action = 'status.php' method = 'post' id = 'sub1'>
<input type = 'submit' name = 'ans' value = 'a'><br>
<input type = 'submit' name = 'ans' value = 'b'><br>
<input type = 'submit' name = 'ans' value = 'c'><br>
<input type = 'submit' name = 'ans' value = 'd'>
</form>
第二页:status.php
<?php
if($_POST['ans'])
{
$ans=$_POST['ans'];
if($ans=='a')
{
$color='blue';
}
if($ans=='b')
{
$color='red';
}
if($ans=='c')
{
$color='green';
}
if($ans=='d')
{
$color='yellow';
}
}
?>
<h4 id = 'q1' style="color:<?php echo $color; ?>">Question 1</h4>
试试这个...
关于php - 当在另一个 PHP 文件中遇到一个操作时,动态地导致一个 PHP 文件发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30860126/