jq +ajax +thinkphp5实现分类选择

2016-12-17 19:59:02来源:CSDN作者:u012493556人点击

第七城市

1.html

  <select class="form-control" name="category" id="category">      <option value="0">一级分类</option>     {foreach $list as $vo}       <option value="{$vo.id}">{$vo.name}</option>     {/foreach}   </select>     <select class="form-control" name="secondcategory" id="secondcategory">      <option value="0">二级分类</option>     </select>

2.jq

/*分类*/$("#category").change(function(){  a=$(this).val();  if(a !=0){        $.ajax({            type: "POST",            dataType: "json",            url: "{:url('stat/getcategory')}",            data: "parentid="+a,         success: function (data) {              $("#secondcategory").html("<option value=''>请选择二级分类</option>");          $.each(data, function(i, item) {                            $("#secondcategory").append("<option value='" + item.id + "'>" + item.name + "</option>");                        });       },            eror: function (data) {             alert("请求超时!")           }         });   }});

3.thinkphp

   /*商品分类统计*/    public function goodscategory()    {        /*一级分类*/        $map = array('uniacid' => 6, 'parentid' => 0, 'level' => 1);        $field = "id,name";        $list = db('ims_ewei_shop_category')->where($map)->field($field)->select();        $this->assign('list', $list);        return $this->fetch();    }    /*获取二级分类*/    public function getcategory()    {        $parentid = intval(input('post.parentid'));        $map = array('uniacid' => 6, 'parentid' => $parentid, 'level' => 2);        $field = "id,name";        $categorylist = db('ims_ewei_shop_category')->where($map)->field($field)->select();        exit(json_encode($categorylist));    }

“`

第七城市

相关文章

    无相关信息

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台