- 相關(guān)推薦
用PHP的checkbox默認(rèn)值輸出方法
php獲取 checkbox復(fù)選框值的方法,checkbox在php讀取值時(shí)要用數(shù)組形式哦,我們讀取這些值用php post獲取是以一個(gè)array形式哦。
php獲取 checkbox復(fù)選框值的方法
復(fù)制代碼 代碼如下:
<html xmlns="http://www.jb51.net/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php獲取 checkbox復(fù)選框值的方法</title>
</head>
<body>
<form name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選一">
復(fù)選一
</label>
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選二">
</label>
復(fù)選二
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選三">
</label>
復(fù)選三
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選四">
</label>
復(fù)選四
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
</body>
</html>
<?
if( $_POST )
{
$value = $_POST['checkbox'];
echo '你選擇了:'.implode(',',$value);
//由于checkbox屬性,我們必須把checkbox復(fù)選擇框的名字設(shè)置為一個(gè)如果checkbox[],這樣php才能讀取,以數(shù)據(jù)形式,否則不能正確的讀取checkbox復(fù)選框的值哦。//腳本之家 jb51.net 整理
}
?>
checkbox在php讀取值時(shí)要用數(shù)組形式哦,我們讀取這些值用php post獲取是以一個(gè)array形式哦,
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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 "您選定的地區(qū)為: ";
foreach ($area_arr as $k=>$v){
echo $v." ";
}
?>
<form id="form1" name="form1" method="post" action="?action=submit">
<p>河北
<label>
<input type="checkbox" id="area" name="area[]" value="河北">
</label>
</p>
<p>河南
<label>
<input type="checkbox" id="area[]" name="area[]" value="河南">
</label>
</p>
<p>山西
<label>
<input type="checkbox" id="area[]" name="area[]" value="山西">
</label>
</p>
<p>山東
<label>
<input type="checkbox" id="area[]" name="area[]" value="山東">
</label>
</p>
<p>江蘇
<label>
<input type="checkbox" id="area[]" name="area[]" value="江蘇">
</label>
</p>
<p>浙江
<label>
<input type="checkbox" id="area[]" name="area[]" value="浙江">
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</p>
</form>
</body>
</html>
php checkbox默認(rèn)選擇問(wèn)題(都是利用的這種原理)
復(fù)制代碼 代碼如下:
<input name="jb51" type="checkbox" value="jiaju" <?php if($myrow[fujia_jiaju]) echo("checked");?>>
【用PHP的checkbox默認(rèn)值輸出方法】相關(guān)文章:
PHP簡(jiǎn)單獲取多個(gè)checkbox值06-10
php的checkbox取值詳細(xì)說(shuō)明12-28
PHP中動(dòng)態(tài)HTML的輸出技術(shù)03-22
用PHP讀取文件的正確方法04-07
PHP中在數(shù)據(jù)庫(kù)中保存Checkbox數(shù)據(jù)06-18
PHP中動(dòng)態(tài)HTML的輸出技術(shù)詳解06-03
用PHP提交from表單的處理方法04-20
Premiere保存與輸出的方法07-31