Rumah > pembangunan bahagian belakang > tutorial php > PHP中获取CHECKBOX交付的内容及checkbox全选

PHP中获取CHECKBOX交付的内容及checkbox全选

WBOY
Lepaskan: 2016-06-13 10:47:34
asal
832 orang telah melayarinya

PHP中获取CHECKBOX提交的内容及checkbox全选

提交页?
<span style="color: #008200;">//js控制全选/取消全选? </span>
<script type="</code"><code class="php string"><span style="color: #0000ff;">"text/javascript"</script>>?
<strong><span style="color: #006699;">function</span></strong> check_all(obj,cName)?
{?
????<strong><span style="color: #006699;">var</span></strong> checkboxs = document.getElementsByName(cName);?
????<strong><span style="color: #006699;">for</span></strong>(<strong><span style="color: #006699;">var</span></strong> i=0;i<checkboxs.length obj.checked></checkboxs.length>
}?
??
??
<form id="</code"> <code class="php string"><span style="color: #0000ff;">"form1"</span> name=<span style="color: #0000ff;">"form1"</span> method=<span style="color: #0000ff;">"post"</span> action=<span style="color: #0000ff;">"receive.php"</span>>?
<table width="</code"> <code class="php string"><span style="color: #0000ff;">"100%"</span>>
???????
???????<td colspan="</code"> <code class="php string"><span style="color: #0000ff;">"2"</span>>?
<div align="</code"> <code class="php string"><span style="color: #0000ff;">"center"</span>>?
<p><input type="</code"><code class="php string"><span style="color: #0000ff;">"checkbox"</span> name=<span style="color: #0000ff;">"all"</span> onclick=<span style="color: #0000ff;">"check_all(this,'checkbox[]')"</span> />全选/全不选
???????????<input type="</code"><code class="php string"><span style="color: #0000ff;">"checkbox"</span> name=<span style="color: #0000ff;">"checkbox[]"</span> value=<span style="color: #0000ff;">"item1"</span> />?
???????????1?
???????????<input type="</code"><code class="php string"><span style="color: #0000ff;">"checkbox"</span> name=<span style="color: #0000ff;">"checkbox[]"</span> value=<span style="color: #0000ff;">"item2"</span> />?
???????????2?
???????????<input type="</code"><code class="php string"><span style="color: #0000ff;">"checkbox"</span> name=<span style="color: #0000ff;">"checkbox[]"</span> value=<span style="color: #0000ff;">"item3"</span> />?
???????????3?
????????????
???????<td></td>
?????
???????<td colspan="</code"> <code class="php string"><span style="color: #0000ff;">"2"</span>>?
??
<div align="</code"> <code class="php string"><span style="color: #0000ff;">"center"</span>>?
???????????<input type="</code"><code class="php string"><span style="color: #0000ff;">"submit"</span> name=<span style="color: #0000ff;">"Submit"</span> value=<span style="color: #0000ff;">"提交"</span> />?
???????????
???????<td></td>
???
??
如果名字不用数组的话,php只能获取到最后一个checkbox的值?
??
receive.php?
<span style="color: #aa7700;">$checkbox</span> = <span style="color: #aa7700;">$_POST</span>[<span style="color: #0000ff;">'checkbox'</span>];?
??
<span style="color: #008200;">/*如果要获取第一个数值就直接中止输出,使用下面代码,相当于radiobox了>.</span>?
<strong><span style="color: #006699;">for</span></strong>(<span style="color: #aa7700;">$i</span>=0;<span style="color: #aa7700;">$i</span><code class="php functions"><span style="color: #ff1493;">count</span>(<span style="color: #aa7700;">$checkbox</span>);<span style="color: #aa7700;">$i</span>++)?
{?
<strong><span style="color: #006699;">if</span></strong>(!<span style="color: #ff1493;">is_null</span>(<span style="color: #aa7700;">$checkbox</span>[<span style="color: #aa7700;">$i</span>]))?
{<span style="color: #aa7700;">$chechvalue</span>=<span style="color: #aa7700;">$checkbox</span>[<span style="color: #aa7700;">$i</span>];<strong><span style="color: #006699;">break</span></strong>;}?
}?
<span style="color: #ff1493;">echo</span> <span style="color: #aa7700;">$chechvalue</span>;?
??
<span style="color: #008200;">/*如果要获取全部数值则使用下面代码*/</span>?
<strong><span style="color: #006699;">for</span></strong>(<span style="color: #aa7700;">$i</span>=0;<span style="color: #aa7700;">$i</span><code class="php functions"><span style="color: #ff1493;">count</span>(<span style="color: #aa7700;">$checkbox</span>);<span style="color: #aa7700;">$i</span>++)?
{?
<strong><span style="color: #006699;">if</span></strong>(!<span style="color: #ff1493;">is_null</span>(<span style="color: #aa7700;">$checkbox</span>[<span style="color: #aa7700;">$i</span>]))?
{<span style="color: #aa7700;">$chechvalue</span>.=<span style="color: #aa7700;">$checkbox</span>[<span style="color: #aa7700;">$i</span>]}?
}?
<span style="color: #ff1493;">echo</span> <span style="color: #aa7700;">$chechvalue</span>;

?

?

转自:http://www.cnblogs.com/freespider/archive/2011/03/18/1988308.html

Label berkaitan:
gt lt
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan