如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
分类表结构
id name tag
<form class="tj_type" method="get"> <label><input type="checkbox" id="all" class="ccc" name="type_all" value="1" <?php echo $type['type_all']==1?"checked":''; ?> /><span>全部</span></label> <?php if(is_array($all_pro_cat)): ?> <?php foreach($all_pro_cat as $k=>$vo): ?> <?php $tag = $vo['tag']; ?> <label><input type="checkbox" class="ccc" name="type_cat[]" value="{$vo['id']}" <?php $tag1= get_pro_cat($vo['id']); $tag_r = $tag1['tag']; ?> <?php echo ($vo['tag']==$type[$tag_r] && $type['type_all']!==1)?"checked":''; ?> /><span>{$vo['name']}</span></label> <?php endforeach; endif; ?> </form> $('.tj_type input[type="checkbox"]').on('change',function(){ var pro_id = {$pro_id}?{$pro_id} : 0; if(pro_id){ var url = '__URL__/url_tran.html?pro_id='+{$pro_id}; }else{ var url = '__URL__/url_tran.html'; } var data = $(".tj_type input,.tj_type select,.tj_type textarea,.tj_type option,.tj_type radio").serialize(); $.ajax({ type:'post', url:url, data:data, dataType:'json', success:function(res){ window.location.replace(res.msg); } }) }); public function url_tran(){ if($_POST){ $url=''; if($_POST['type_all']==1){ $type['type_all'] = 1; $url .= 'type_all=1&'; }else{ $type['type_all'] = 0; } if($_POST['type_cat']){ foreach($_POST['type_cat'] as $k=>$vo){ $tag1= get_pro_cat($vo); $tag = $tag1['tag']; $type[$tag] = 1; $url .= ($tag.'=1&'); } $_SESSION['type'] = $type; }else{ $type['type_jd'] = 0; $_SESSION['type'] = 0; } if($_GET['pro_id']){ $url_r = '//'. $_SERVER['SERVER_NAME'].'/index.php/default/index.html?pro_id='.$_GET['pro_id'].'&'. $url; }else{ $url_r = '//'. $_SERVER['SERVER_NAME'].'/index.php/default/index.html?'. $url; } $this->jssuccess($url_r); die; } }