zoukankan      html  css  js  c++  java
  • js 把url参数转对象



    //注意url中要含?
     function getParameterByName(name, url) {
                if (!url) {
                    url = window.location.href;
                }
                name = name.replace(/[[]]/g, "\$&");
                var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                    results = regex.exec(url);
                if (!results) return null;
                if (!results[2]) return '';
                return decodeURIComponent(results[2].replace(/+/g, " "));
            }
    调用:getParameterByName("userID","?userID=JeoOrCXxyiOFxbYaGL40kw==&userPwd=sdFo2ziUw8HyLRKd4i6GAQ==&userName=高聪");
    得到:userID

     var parseQuery = function (query) {
                var reg = /([^=&s]+)[=s]*([^&s]*)/g;
                var obj = {};
                while (reg.exec(query)) {
                    obj[RegExp.$1] = RegExp.$2;
                }
                return obj;
            }
    调用:
    parseQuery("userID=JeoOrCXxyiOFxbYaGL40kw==&userPwd=sdFo2ziUw8HyLRKd4i6GAQ==&userName=高聪")
    得到

     
     
     
  • 相关阅读:
    Go标准库之tar
    redis必知必会
    GORM CRUD指南
    GORM入门指南
    MUI中tap点击事件点击一次连续申请两次
    Go代码启动默认浏览器
    Go实现JWT
    Go Micro
    protobuf初识
    英语作文
  • 原文地址:https://www.cnblogs.com/gaocong/p/6109967.html
Copyright © 2011-2022 走看看