在PHP中checkBox复选框我们以一般是使用数组形式来做的,这样在 PHP 中获取复选框值时我们会以数组形式存储的,所以只要遍历数组即可实现,代码如下:
- <html>
- <head>
- <title>获取复选框的值</title>
- </head>
- <body>
- <form action="result.PHP" method="POST">
- <input type="checkBox" name="year[]" value="1">1
- <input type="checkBox" name="year[]" value="2">2
- <input type="checkBox" name="year[]" value="3">3 <br>
- <input type="submit" value="提交" />
- </form>
- </body>
- </html>
- <?PHP
- foreach($_POST['year'] as $item){
- echo $item."<br>";
- }
- ?>