zoukankan      html  css  js  c++  java
  • 黑马旅游网 解析url查询字符串

     1 function getUrlParam(name) {
     2     let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
     3     let r = window.location.search.substr(1).match(reg);
     4     return r != null ? r[2] : null;
     5 }
     6 
     7 function getQueryArgs(){
     8     let qs=location.search.length ? location.search.substring(1) : "";
     9     let args={};
    10     let items=qs.length ? qs.split("&") : [];
    11 
    12     for(let item of items){
    13         let pair=item.split("=");
    14         if(pair[0].length){
    15             args[decodeURIComponent(pair[0])]= decodeURIComponent(pair[1]);
    16         }
    17     }
    18     return args;
    19 }
    20 
    21 function getQueryStringArgs(){
    22     var qs=location.search.length ? location.search.substring(1) : "";
    23     var args={};
    24     var items=qs.length ? qs.split("&") : [];
    25     var item=null,
    26         name=null,
    27         value=null,
    28         len=items.length;
    29     for(var i=0;i<len;i++){
    30         item=items[i].split("=");
    31         if(item[0].length){
    32             name=decodeURIComponent(item[0]);
    33             value=decodeURIComponent(item[1]);
    34             args[name]=value;
    35         }
    36     }
    37     return args;
    38 }
    39 
    40 function getQuery() {
    41     let search = location.search;
    42     // alert(search);
    43 
    44     //没有查询参数
    45     let i = search.indexOf("?");
    46     if( i == -1){
    47         return {};
    48     };
    49 
    50     //去除问号
    51     search = search.substring(i + 1);
    52 
    53     //得到参数
    54     let result = {};
    55     let items = search.split("&");
    56     for(let item of items){
    57         let split = item.split("=");
    58         // alert(split[0]);
    59         // alert(split[1]);
    60         if(split[0]){
    61             result[decodeURIComponent(split[0])] = decodeURIComponent(split[1]);
    62         }
    63     }
    64     return result;
    65 }
    解析url查询字符串
  • 相关阅读:
    Python学习笔记:pandas.read_csv分块读取大文件(chunksize、iterator=True)
    Python学习笔记:os.stat().st_size、os.path.getsize()获取文件大小
    7-1 打印沙漏
    7-1 币值转换
    7-1 抓老鼠啊~亏了还是赚了?
    第四周编程总结哦也
    2018秋寒假作业6—PTA编程总结3
    PTA编程总结3
    PTA编程总结1
    秋季学期学习总结
  • 原文地址:https://www.cnblogs.com/mozq/p/10911473.html
Copyright © 2011-2022 走看看