如果要解析以下地址中的channel_tag字段 http://saas.ceshi.test.maiyiru.com/invoice/?channel_tag=meituan&keyword=222http://saas.wulongmei.test.maiyatian.com/invoice/?channel_tag=meituan&keyword=222
var href = window.location.href || '你的url地址'
var query = getQueryVariable( href, '你要查询的字段' ) || ''
var getQueryVariable = function (url, key) {
if (!url || !key) return ''
let ret = getQueryVariables(url, key);
return ret[key] || ''
}
var getQueryVariables = function (url) {
if (!url) return ''
let ret = {},
seg = url.substr(url.indexOf('?') + 1, url.length).split('&'),
len = seg.length, i = 0, s
for (; i < len; i++) {
if (!seg[i]) {
continue
}
s = seg[i].split('=')
ret[s[0]] = s[1]
}
return ret
}
console.log(query)