Html 复合 PHP 实现单选框多选框的代码
2022-05-24
话不多说,直接上代码即可,当然可以实现多个选项同时传参啦
多选框:
<!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>
发表评论: