zoukankan      html  css  js  c++  java
  • jquery分隔Url的param方法

    最近需要分隔url的querystring,用到了特意记录一下。
    方法:
    //获取url中的params
    var search = location.search.substring(1);
    //params转换object(javascript)
    search?JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
                  function(key, value) { return key===""?value:decodeURIComponent(value) }):{}

    例子:
    search = "abc=foo&def=%5Basf%5D&xyz=5&foo=b%3Dar";
    function test(search)
    {
       return search?JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g,'":"') + '"}', function(key, value) { return key===""?value:decodeURIComponent(value) }):{}
    }
    View Code
    返回
    Object {abc: "foo", def: "[asf]", xyz: "5", foo: "b=ar"}
     
  • 相关阅读:
    Beta 冲刺day 6
    Beta冲刺day5
    Beta冲刺day4
    Beta 冲刺day3
    Beta 冲刺day2
    Beta冲刺day1
    Beta预备
    城市安全风险管理项目Postmortem结果
    项目总结
    Alpha冲刺置顶随笔
  • 原文地址:https://www.cnblogs.com/wuyb/p/5527088.html
Copyright © 2011-2022 走看看