getParameterByName获取url链接中的参数?
const getParameterByName = function (name) {
let values = decodeURIComponent((location.search.match(RegExp('[?|&]' + name + '=([^\&]+)')) || [, null])[1]);
return isNullOrEmpty(values) || values == 'null' ? '' : values;
};
?// 举例使用:
// url:httsp://www.linking.com.cn?username=lisa&age=17
let username =?getParameterByName('username')
console.log(username) // lisa
其中,方法isNullOrEmpty可查阅这里连接:
isNullOrEmptyhttps://blog.csdn.net/q1ngqingsky/article/details/120211929?spm=1001.2014.3001.5501https://blog.csdn.net/q1ngqingsky/article/details/120211929?spm=1001.2014.3001.5501
|