【发布时间】:2020-12-13 04:56:11
【问题描述】:
下面的代码中有 4 个文本框。您可以在这四个文本框中键入您想要的所有内容,当您单击“选择一个”按钮时,您将返回您在文本框中输入的文本。但我想将这些文本框更改为下拉列表,您可以从中选择四个不同的团队,当您单击“选择一个”按钮时,您将随机获得您选择的四个团队之一。
<?php
error_reporting(0);
if(isset($_POST['submit']))
{
$team1=$_POST['team1'];
$team2=$_POST['team2'];
$team3=$_POST['team3'];
$team4=$_POST['team4'];
$teams=array
(
"1" =>"$team1",
"2" =>"$team2",
"3" =>"$team3",
"4" =>"$team4",
);
$random = rand(1, 4);
}
?>
<html>
<form action="index.php" method="POST">
Enter the team name<input type="text" name="team1" value="<?php echo $team1 ?>"><br>
Enter the team name<input type="text" name="team2" value="<?php echo $team2 ?>"><br>
Enter the team name<input type="text" name="team3" value="<?php echo $team3 ?>"><br>
Enter the team name<input type="text" name="team4" value="<?php echo $team4 ?>"><p>
<input type="submit" name="submit" value="Pick One!"><br>
</form>
<?php
print $teams["$random"];
?>
</html>
【问题讨论】:
-
目前尚不清楚您的实际问题是什么。这与下拉菜单有什么关系?
-
对不起,我试着解释得更好。所以现在,有 4 个输入文本的地方。你可以写任何你想要的,当你点击“选择一个”按钮时,你会得到任何文本您之前输入的内容。我想将这些输入文本位置更改为下拉列表,您可以在其中选择一些团队,当您单击“选择一个”时,您将随机获得 1 个团队。