php獲取 checkbox複選框值的方法,checkbox在php讀取值時要用數組形式哦,我們讀取這些值用php post獲取是以一個array形式哦。
php獲取 checkbox複選框值的.方法
複製代碼 代碼如下:
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php獲取 checkbox複選框值的方法</title>
</head>
<body>
<form name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="複選一">
複選一
</label>
<label>
<input type="checkbox" name="checkbox[]" value="複選二">
</label>
複選二
<label>
<input type="checkbox" name="checkbox[]" value="複選三">
</label>
複選三
<label>
<input type="checkbox" name="checkbox[]" value="複選四">
</label>
複選四
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
</body>
</html>
<?
if( $_POST )
{
$value = $_POST['checkbox'];
echo '你選擇了:'ode(',',$value);
//由於checkbox屬性,我們必須把checkbox複選擇框的名字設置為一個如果checkbox[],這樣php才能讀取,以數據形式,否則不能正確的讀取checkbox複選框的值哦。//腳本之家 整理
}
?>
checkbox在php讀取值時要用數組形式哦,我們讀取這些值用php post獲取是以一個array形式哦,
複製代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php獲取多選框checkbox值</title>
</head>
<body>
<?php
$area_arr = array();
if($_GET['action']=="submit"){
$area_arr = $_POST['area'];
}
echo "您選定的地區為: ";
foreach ($area_arr as $k=>$v){
echo $v." ";