首页 HTML/css/Js正文

Html 复合 PHP 实现单选框多选框的代码

欲儿 HTML/css/Js 2022-05-24 260 0

话不多说,直接上代码即可,当然可以实现多个选项同时传参啦

image.png

多选框:

<!DOCTYPE html>
<html>

</body>
<h2>Which hobby do you like best!</h2>
<form action="" method="post">
Hobby: 	<input type="checkbox" name="answer[]" value="Eatting"/>Eatting
	<input type="checkbox" name="answer[]" value="Sleeping"/>Sleeping
	<input type="submit" name="submit" value="submit"/>
</form>




<?php
	echo "Your answer is that :";
	$result = '';
	for($i=0;$i<count($_POST['answer']);$i++)
	{
		$result = $result . $_POST['answer'][$i].',';
	}
	echo $result;
?>

</body>
</html>

同样的道理还有单选框

<DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>


<script type="text/javascript">
</script>


<style>





</style>
</head>
<body>
<h1> Which season do you like best? </h1>
<form action = "" method = "post">
	<div class="dxan">
	<input type = "radio" name = "option" value = "Spring" checked>A.Spring
	<input type = "radio" name = "option" value = "Summer" >B.Summer
	<input type = "submit" name = "handin" value = "提交"  style= "margin-left:50px;"> 
	</div>
</form>
<?php
	echo "Your answer is that :";
	$result = $_POST['option'];
	echo $result;
?>



</body>

</html>


版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论