zoukankan      html  css  js  c++  java
  • 前后端不分离之分页 url

     //将对象转成url 参数
        var urlEncode = function(param, key, encode) {
            if (param==null) return '';
            var paramStr = '';
            var t = typeof (param);
            if (t == 'string' || t == 'number' || t == 'boolean') {
                paramStr += '&' + key + '='  + ((encode==null||encode) ? encodeURIComponent(param) : param);
            } else {
                for (var i in param) {
                    var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i)
                    paramStr += urlEncode(param[i], k, encode)
                }
            }
            return paramStr;
        }
        var parameterList = {};
        var parameter;
        var urlPath;
        var parameterArr;
        if(window.location.href.indexOf('?')==-1){
            parameterList = {};
            urlPath = window.location.href+'?';
        }else {
            parameter = window.location.href.substring(window.location.href.indexOf('?')+1);
            urlPath = window.location.href.substring(0,window.location.href.indexOf('?')+1);
            parameterArr = parameter.split("&");
            for(var key in parameterArr){
                parameterList[parameterArr[key].substring(0,parameterArr[key].indexOf('='))] = parameterArr[key].substring(parameterArr[key].indexOf('=')+1)
            }
        }
        //跳转字符串函数
        function toHref(){
            window.location.href =urlPath+urlEncode(parameterList).slice(1)
        }
    
        //初始化 全部清除
        if($('.result a').length>0){
            $('.clearAll').show()
        }
        // 专利分类筛选
        $('#patentClassList a').on('click',function () {
            parameterList['page'] = 1;
            parameterList['ptype'] = $(this).attr('data-id');
            toHref();
        })
        //行业分类筛选
        $('#industryList a').on('click',function () {
            parameterList['page'] = 1;
            parameterList['zlhyfl'] = $(this).attr('data-id');
            toHref();
        })
        //年份筛选
        $('#yearList a').on('click',function () {
            parameterList['page'] = 1;
            parameterList['ythree'] = $(this).attr('data-id');
            toHref();
        })
        //行业小类
        $('#locList a').on('click',function () {
            parameterList['page'] = 1;
            parameterList['zlhycfl'] = $(this).attr('data-id');
            toHref();
        })
        $('.unlimited').on('click',function () {
            parameterList['page'] = 1;
            parameterList['zlhycfl'] = '';
            toHref();
        })
        $('#locMore').on('click',function () {
            $(this).parents('.screenItem').toggleClass('active');
            $(this).toggleClass('active');
        })
        //已选条件点击
        $('.result a').on('click',function () {
            parameterList['page'] = 1;
            parameterList[$(this).attr('data-name')] = '';
            toHref();
        })
        $('.clearAll').on('click',function () {
            parameterList = {};
            parameterList['page'] = 1;
            toHref();
        })
  • 相关阅读:
    ABC065D Built[最小生成树]
    loj2718 「NOI2018」归程[Kruskal重构树+最短路]
    BZOJ1821 部落划分[最小生成树]
    BZOJ4777 [Usaco2017 Open]Switch Grass[最小生成树+权值线段树套平衡树]
    CF888G Xor-MST[最小生成树+01trie]
    Atcoder CODE FESTIVAL 2016 Final G
    BZOJ4883 [Lydsy1705月赛]棋盘上的守卫[最小基环树森林]
    BZOJ3714 [PA2014]Kuglarz[最小生成树]
    BZOJ1601 [Usaco2008 Oct]灌水[最小生成树]
    CF892E Envy[最小生成树]
  • 原文地址:https://www.cnblogs.com/MR-cui/p/10796610.html
Copyright © 2011-2022 走看看