联动菜单 模糊查询

联动菜单 根据一级菜单利用AJAX查询二级出菜单 然后插入二级菜单

<form  action="{:url('index/product1')}" method="post" class="form-center">
                  <select id="classify" class="header-left" name="name1">
                    <option value="au"  >产品分类</option>
                    {volist name="res" id="vo"}    
                    <option value="{$vo.product_cat_id}"  >{$vo.name}</option>
                    {/volist}
                  </select>

                  <select id="classifys" class="header-left" name="name">
                    <option value="">产品型号</option>
        
                     
                  </select>
            
                <input type="search" name="title" placeholder="请输入关键字" class="header-left">
                <button type="submit">
                    <i class="fa fa-search"></i>
                </button>
            </form>
<script type="text/javascript" charset="utf-8" >
    $('#classify').change(function(event) {
        var data=$('#classify option:selected').val();
                  $.ajax({
                    url:"{:url('index/fenls')}",
                    dataType: "json",
                    type: 'POST',
                    data: {id:data},
                    success: function(data){
                     console.log(data);
                      $("#classifys").empty();
                        $.each(data,function(key,values){
                            $(values).each(function(){
                                 $("#classifys").append('<option value="'+this.product_cat_id+'">'+this.name+'</option>');     
                            });
                        });
                    }, 
                
                });
    });
    
    

</script>
//接收传过来的ID 查询 再返回给前台
  public function fenls(){
    
        $id=input('post.id');
        
        $lx = Db::name('product_category')->where('pid',$id)->select();
        echo json_encode($lx);
        return;
  }

//判断最终查询where条件  
            $name=input('post.name');
        $title=input('post.title');
        //print_r($title);exit;
        //$data=array('title'=>$title,'category_id'=>$name);
    
            if($name){
                $where['category_id'] =$name;    
        }else{
            $where['title']=['like',"%".$title."%"];
             
        }

    

此处评论已关闭

[player id="719102"/]