→ GitHub
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title></title> </head> <body> <script> var getRequest = (function() { var request = location.search // ? '' // ?222 '?222' // ?a=222 '?a=222' // ?a=中2 '?a=%E4%B8%AD2' var result = {} if (request.indexOf('?') !== -1) { request = request.substr(1).split('&') var i = 0 var len = request.length for (; i < len; i++) { var item = request[i].split('=') result[item[0]] = decodeURIComponent(item[1]) } } return result })() </script> <script> console.log(getRequest['a']) </script> </body> </html>