<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>url</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
<script>
function parseQueryString(url) {
var params = {};
var arr = url.split("?");
var arr1 = arr[1].split("&");
for (var i = 0; i < arr1.length; i++) {
arr2 = arr1[i].split('=');
if (!arr2[1]) {
params[arr2[0]] = 'true';
} else if (params[arr2[0]]) {
var arr3 = [params[arr2[0]]];
arr3.push(arr2[1]); params[arr2[0]] = arr3;
} else {
params[arr2[0]] = decodeURI(arr2[1]);
}
}
console.log(params);
}
var url = 'http://www.baidu.com/?user=huixin&id=123&id=456&city=%E5%8C%97%E4%BA%AC&enabled';
parseQueryString(url);
</script>
</body>
</html>
运行结果: