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();
        })
  • 相关阅读:
    Sqlite数据库sqlite3命令
    cerr
    include 尖括号和双引号
    C程序存储空间布局——各数据段的内存位置
    贪心算法
    CodeBlocks
    O(n)是什么
    微软公司面试题
    CSS3---结构性伪类选择器—not
    CSS3---结构性伪类选择器-root
  • 原文地址:https://www.cnblogs.com/MR-cui/p/10796610.html
Copyright © 2011-2022 走看看