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=高聪
")
得到
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+MAAACTCAIAAABqLF/bAAAOKElEQVR4nO3dPU7rTBsGYC8oEkJiL6lcZSMpaFKwjDRUaVhDGspIn8QmUiIhYL7CfzP2OPy8h5MJ57pEARN7xvELem8/eexTBQAAoDzVuQ8AAADIkNQBAKBE1f8AAIDyqKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDwF+3q8PVJhw2oarPfSicm18G5l1KUn+6u6k6N3dP8Y/d2LkPEQA+ZxeqOoRDuLoKh3MfC71NfY7/HH4ZOOVSknoITVpvE3n0bfejtA7AZajrEHK5sK5C1X1dbb446SFcdfvuPjyAaKFdCLs6VFVb0G1eqj+cYuYANofxSHxI7ULR12YmnO7qUE2Sax2dmc3VR2cpWr15O+3qM4H4sBm/1J6lbrDZ/Rsn5rS5XwYIIfxsUh/F6YdVVa0e+m877VA01u3zsKpu7p6a8dXDqaTe799NBgAX6RCuvtUCUfepd/dBE0UdBfHNVbvXrh52/05M//Qh1XEa3p2K2nUuUg+Dh1CfvJiJV+9X2VzNRu3NJllxczXk+373+ge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3fzN0n9aYjYD6sucj+shvTdZPT4h2ba7LoAcCbZXD43IqnDb3eGpD4abl/KbJiOJvv3pfRptM5eEKQ/9EeQXxcAzuSTNfX4G0kdfq9z1NT7JpTuxbR7pW9PmUnq/QtPo06YUQPMx0l9Zl0AKNi0++V0sgcu1nn61EMa1zNV9naHfFJvM3qf1B9W4/b0zyd1zekAlOCTD34JM096EdDhNzpbUk82yfedzCf15rXV6qarvUd7f7H7RRUdgBKcjtofJvUw0wwDXLIf/XuOo/pwe2h7E2k/2oXtOEmvpl3k+Zr8uPG9Gf5sUs+vCwB/XZy/TzxDPUSJfPT4l9mnqgOX6of/mOPnIo6e6TJ+MuJ09GRST1L2sMzN3d0Xaur5dQHgrzvd0zLN8SGN7NmpgAvnjxkACvD5mnq8i2o6/Gr+pAGgACdC9twTXUbVdw9+gV/HnzQAAJRIUgcAgBJJ6gAAUCJJHQAASiSpAwBAiar/AQAA5VFTBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoESSOgAAlEhSBwCAEknqAABQIkkdAABKJKkDAECJJHUAACiRpA4AACWS1AEAoET/B5Nvlbclap1UAAAAAElFTkSuQmCC" alt="" />
js 把url参数转对象的更多相关文章
- JS解析URL参数为对象
曲不离口,拳不离手 JS小编程练习之一:解析URL参数为对象 url:http://www.baidu.com/we/index.html?id=098&aaa=123&ccc=456 ...
- js获取url参数的方法
js获取url参数的方法有很多. 1.正则分析 function getQueryString(name) { var reg = new RegExp("(^|&)" + ...
- get方法与post方法的区别与js获取url参数的方式
1.get方法与post方法的区别: 区别一:get重点在从服务器上获取资源,post重点在向服务器发送数据:区别二:get传输数据是通过URL请求,以field(字段)= value的形式,置于UR ...
- js获取url参数,操作url参数
function getParam(key) { var tmp = location.search; tmp = decodeURIComponent(tmp); var index = tmp.i ...
- js javascript 获取url,获得当前页面的url,静态html文件js读取url参数
获得当前页面的url window.location.href 静态html文件js读取url参数 location.search; //获取url中"?"符后的字串 下边为转载的 ...
- 【js操作url参数】获取指定url参数值、取指定url参数并转为json对象
获取指定url参数值 /* 获取某url中的某参数值 调用:GetUrlQueryString("[url地址]","[参数名]"); */ function ...
- js修改url参数,无刷新更换页面url
一.js修改地址栏URL参数 function changeURLPar(destiny, par, par_value) { var pattern = par + '=([^&]*)'; ...
- 用js 获取url 参数 页面跳转 ? 后的参数
记得之前在原来的公司写过这个东西,但是还是忘记怎么接住参数了,只知道怎么把id传过去! 问了身边的大佬 他首先推荐了我一个链接是别人写好的方法 附上链接地址:http://blog.csdn.net/ ...
- js截取url参数
举例说明,比如http://localhost:2019/blog/getCommentListInfo?postId=1如何获取postId=1这个参数值呢?很简单通过下面代码即可获取,如: win ...
随机推荐
- LeetCode OJ-- Single Number II **@
有一列数,其中有1个数出现了1次,其它数都出现了3次,求这个数. class Solution { public: int singleNumber(int A[], int n) { ) ; ; ; ...
- 爱上WPF,努力才会有希望!
从WinForm转向WPF开发已经有两个多月了,通过不断深入地学习与运用,现在是越来越爱它了.它实在是太强大了.运用WPF,你不仅可以做Win界面,也可以很快转向Web开发,因为Silverlight ...
- 2016某知名互联网公司PHP面试题及答案
1 字符串"\r","\n","\t","\x20"分别代表什么 答案: "\r"代表的含义是: 在 ...
- Qt 为tableview的item添加网格线
使用qss可以显示每个item的网格: selection-background-color: rgb(170, 170, 127); gridline-color: rgb(255, 255, 25 ...
- nginx负载均衡最新
配置conf文件 #user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log no ...
- <数据结构与算法>之字符串,散列,布隆过滤器。
1:字符串 字符串是一组由数字,字符,下划线的一串字符,是特殊的一维数组. 2:字符串的应用 字符串移位包含问题: 例:给定两个字符串s1和s2,要求判断s2是否能被s1做循环移位得到字符串包含.例如 ...
- bzoj1179(Atm)
---恢复内容开始--- 1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MB Description Input 第一行包含两个整 ...
- Oracle学习笔记1
查看登录用户 show user; 启用scott用户 alter user scott account unlock; 操作表空间 select * from dba_tablespaces; se ...
- sqlserver和oracle的递归查询
1.sqlserver递归查询方式 CTE: if OBJECT_ID('tb','N') is not null drop table tb; create table tb(id va ...
- 尝试u3d中将代码与编辑器分离
最近与朋友交流,他一直是做端游,最近接触了u3d以后无法忍受代码与配置文件,美术资源全部纠缠在一起的状况,于是一直在琢磨怎么将编辑器与代码彻底分离. 自己也抽空研究一下,碰到一些问题先记录下来. 首先 ...