Home  >  Article  >  Backend Development  >  怎样才能获取checkbox选择的值?解决方法

怎样才能获取checkbox选择的值?解决方法

WBOY
WBOYOriginal
2016-06-13 12:27:321308browse

怎样才能获取checkbox选择的值?


这是前台页面,其中“所在部门”和“副职姓名”是jquery从另一个页面get的数据,返回的就是下面的checkbox。我试了一下,从这个页面用js好像找不到这些checkbox,所以只有用php来做了,但是做不出来,下面是部分代码:user是checkbox的name。

$user=$_POST['user'];
$arr=array();
$darr=array();
$darr=  array_diff($arr,$user);
            if(!empty($user)){
                 for($i=0;$i                     if($user=="checked")
                //echo "<script>alert('dfh')</script>";
                $db->query("update members set fuchu='".$_POST['fuchu']."' where uid='".$user[$i]."'");
                } 
            }
           
            if(!empty($darr)){
                for($j=0;$j                    $rowf=$db->get_one("select * from members where fuchu=".$_POST['fuchu']);
                    if($darr[$j]==$rowf['uid'])
                        unset($darr[$j]);
                    else
                        $db->query("update members set fuchu='0' where uid='".$darr[$j]."'");
                }
            }

我是用的array_diff方法,将选中的和没选中的checkbox区分开来。但是我试了好多遍,主要问题是$_POST['user']返回的是点击的数据,无论是否选中,这样的话如果原来是选中的,我想取消选中的话就做不到,如何能挑出取消选中的数据?
------解决思路----------------------
提交的数据 Array ( [depart] => 2 [fuchu] => 112 [submit] => 提交 ) 中并没有 user 项
没有被提交,那自然也就无法处理

#2 下半部只是 php 生成复选框串的代码,并不表示复选框就一定放进表单里去了
------解决思路----------------------
你是这样使用提交的数据的:$user=$_POST['user'];
如果 print_r($_POST); 只显示 Array ( [depart] => 2 [fuchu] => 112 [submit] => 提交 )
你怎么去用 $user ???

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn