分类目录: html5
js获取当前网址的参数,js获取网址?或者&后面的参数
Post date:
Author: cyy
标签: js
Number of comments: no comments
js获取当前网址的参数,js获取网址?或者&后面的参数
效果如下:
直接上代码:
function getParamsCode (paramName) {
var pathArr = (window.location.href).match(/([^?=&]+)(=([^&]*))/g)
var path = {}
if (pathArr) {
path = pathArr.reduce(
function(a, v) {
(a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1));
return a
},
{}
)
}
return path[paramName] || undefined
}