直接上代码吧
var getParmasByKey = (url = location.href, key='') => (url.match(new RegExp(('([&?])'+key+'=([^&#]*)')))||[])[2]
var url = 'http://localhost/test?name=wind&id=50012&age=27&test=&dd=22&cc=#first'
console.log(getParmasByKey(url, 'name'))
console.log(getParmasByKey(url, 'id'))
console.log(getParmasByKey(url, 'age'))
console.log(getParmasByKey(url, 'test'))
console.log(getParmasByKey(url, 'dd'))
console.log(getParmasByKey(url, 'cc'))
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。