前端代码:

<formmethod="post"action=""onsubmit="set()"><divclass="layui-form-item"><inputtype="checkbox"value="1"name="parents"title="1"><inputtype="checkbox"value="2"name="parents"title="2"><inputtype="checkbox"value="3"name="parents"title="3"><inputtype="hidden"name="parent_cat"id="parent"value=""></div><divclass="layui-form-item"><buttonclass="layui-btn"type="submit">下一步</button></span></div></form><script>functionset(){varparents=check_arr('parents');$('#parent').val(parents);}functioncheck_arr($str){varstr=document.getElementsByName($str);varobjarray=str.length;varchestr="";for(i=0;i<objarray;i++){if(str[i].checked==true){chestr+=str[i].value+",";}}returnchestr;}</script>

后台代码:

$parent_cat=$_POST['parent_cat'];//删除最后一个逗号(post过来的是"1,2,3,")//处理之后变为("1,2,3")$parent_cat=substr($parent_cat,0,strlen($parent_cat)-1);//然后可以分成数组进行处理$pros=explode(',',$parent_cat);