JS获取url中的参数值
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>queryString方法</title> </head> <body> <script> function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r = location.search.substr(1).match(reg); if(r != null){ return unescape(decodeURI(r[2])); } return null; } //调用 console.log(getQueryString('nickname')); </script> </body> </html>
一个人静静地坐在电脑前写代码,有种武林高手闭关修炼的感觉!