在 html 通过js 获取查询参数
file:///E:/test.html?a=1&b=2
<script type="text/javascript"> var getParameters = function() { var search = window.location.search; var obj = {}; if (search != '') { // window.location.search '' or start with '?' search = search.substring(1); var keypairArray = search.split('&'); for (i in keypairArray) { keypair = keypairArray[i]; partArray = keypair.split('='); if(partArray.length == 2){ obj[partArray[0]] = partArray[1]; } } } return obj; } console.dir(getParameters()); </script>
结果: