在php中checkbox復(fù)選框我們以一般是使用數(shù)組形式來做的,這樣在 php 中獲取復(fù)選框值時我們會以數(shù)組形式存儲的,所以只要遍歷數(shù)組即可實現(xiàn),代碼如下:
- <html>
- <head>
- <title>獲取復(fù)選框的值</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代碼,代碼如下:
- <?php
- foreach($_POST['year'] as $item){
- echo $item."<br>";
- }
- ?>
新聞熱點
疑難解答