PHP中获取CHECKBOX提交的内容及checkbox全选
<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>
/>?
???????????
<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>
/>?
???????????
<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>
/>?
???????
<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>
/>?
如果名字不用数组的话,php只能获取到最后一个checkbox的值?
<span style="color: #aa7700;">$checkbox</span>
=
<span style="color: #aa7700;">$_POST</span>
[
<span style="color: #0000ff;">'checkbox'</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>
;?
<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
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Neueste Artikel des Autors
2024-10-22 09:46:29
2024-10-13 13:53:41
2024-10-12 12:15:51
2024-10-11 22:47:31
2024-10-11 19:36:51
2024-10-11 15:50:41
2024-10-11 15:07:41
2024-10-11 14:21:21
2024-10-11 12:59:11
2024-10-11 12:17:31