web-utils-super
Version:
前端函数库
23 lines (21 loc) • 644 B
JavaScript
/**
* @desc 获取url参数中对应key的值
* @param {String} key
* @param {String} url
* @return {String}
*/
function getQueryString(key, url) {
let winObj = arguments.length > 1 ? arguments[1] : window
let reg = new RegExp('(^|\\?|&)' + key + '=([^&]*)(\\s|&|$)', 'i')
if (arguments.length <= 1) {
if (typeof winObj.location != 'object') {
winObj = window
}
if (reg.test(winObj.location.href)) return unescape(RegExp.$2.replace(/\+/g, ' '))
return ''
} else {
if (reg.test(url)) return unescape(RegExp.$2.replace(/\+/g, ' '))
return ''
}
}
module.exports = getQueryString