点击事件,选择按钮,点击从前端传到后台,查询数据,并返回前段,显示出来。---tp5

 
  
//这是HTML页面
<div class="form-group">
                        <label class="col-sm-3">听读写说分类label>
                        <div class="col-sm-8">
                            <a class="btn btn-sm btn-danger btn-mid" οnclick="searchSet({mid:-1,class:'btn-mid',e:this})" href="#">全部a>
                            {volist name="listcate" id="list"}
                            <a class="btn btn-sm btn-default btn-mid" οnclick="searchSet({mid:{$list.id},class:'btn-mid',e:this})" href="#">{$list.catename}a>
                            {/volist}

                            
                        div>
                    div>
                    <div class="form-group">
                        <label class="col-sm-3">图视频分类label>
                        <div class="col-sm-8">
                            <a class="btn btn-sm btn-danger btn-pid" οnclick="searchSet({pid:-1,class:'btn-pid',e:this})" href="#">全部a>
                            <a class="btn btn-sm btn-default btn-pid" οnclick="searchSet({pid:1,class:'btn-pid',e:this})" href="#">图片a>
                            <a class="btn btn-sm btn-default btn-pid" οnclick="searchSet({pid:2,class:'btn-pid',e:this})" href="#">视频a>
                        div>
                    div>

                div>


            form>
        div>
    div>
div>
 
  
 
  
 
  
 
  
//这是JS页面也可以说是jq
 
  
<script>

    var searchData = {
        mid: null,
        pid: null,
        page: null
    };

    searchSet({});

    function searchSet(set){
        $("." + set.class).removeClass("btn-danger");
        $("." + set.class).addClass("btn-default");
        if(set.e) set.e.setAttribute("class","btn btn-sm btn-danger " + set.class);
        if(set.mid) searchData.mid = set.mid == -1 ? null : set.mid;
        if(set.pid) searchData.pid = set.pid == -1 ? null : set.pid;
        if(set.page) searchData.page = set.page;

        search();
    }

    function search(){

        $.post("set_text" ,searchData ,function(result){
            var dataObj = eval('(' + result + ')');
            var dataList = dataObj.data;
            var domHtml ='';
                for (let i in dataList) {
                domHtml += "";
                domHtml += ""+dataList[i].id+"";
                domHtml += ""+dataList[i].nickname+"";
                domHtml += "+dataList[i].url+">";
                domHtml += ""+dataList[i].follow_num+"";
                domHtml += ""+dataList[i].followers_num+"";
                domHtml += ""+dataList[i].forwarding_num+"";
                domHtml += ""+dataList[i].comment_num+"";
                domHtml += ""+dataList[i].like_num+"";
                var sTitle =dataList[i].content;
                    if(sTitle.length >8){ sTitle = sTitle .substring(0,8)+"..."}
                var sveido=dataList[i].video_url;
                var sForwarding=dataList[i].is_forwarding;
                if(sForwarding='0'){
                    sForwarding='是';
                }else{
                    sForwarding='否';
                }
                    var surl_img=dataList[i].img_url;
                    if(surl_img='null'){
                        surl_img='无'
                    }else{
                        surl_img=dataList[i].img_url;

                    }
                domHtml += ""+sTitle+"";
                domHtml += "";
                domHtml += "+surl_img+">"+surl_img+"";
                domHtml += "+sveido+">";
                domHtml += ""+dataList[i].date+"";
                domHtml +="";
            }
            $("#list").html(domHtml);
            $('#callBackPager').extendPagination({
                totalCount: dataObj.total,
                showCount: 10,
                currentPage: dataObj.current_page,
                limit: dataObj.per_page,
                callback: function (curr) {
                    searchSet({page:curr});
                }
            });

        });
    }
//php界面
 
  
public function text(){

    $user= new WeiboArticle();
    $this->setProject('weibo');
    $mid=$this->request->post('mid');
    $pid=$this->request->post('pid');

    if($mid){
        $user->where("project_mid",$mid);
    }

    if($pid){
        $user->where("project_pid",$pid);
    }
    if($pid&&$mid){
        $user->where("project_pid",$pid);
        $user->where("project_mid",$mid);
    }

    $list = $user->paginate(5);
    echo json_encode($list);

}

 
  
 
  

你可能感兴趣的:(点击事件,选择按钮,点击从前端传到后台,查询数据,并返回前段,显示出来。---tp5)