<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>提取URL的搜索字符串中的参数</title>
</head>
<body>
<script>
/*var args = urlArgs();//从URL中解析参数
var q = args.q || '';//如果参数定义的话就使用参数,否则使用一个默认值
var n = args.n ? parseInt(args.n):10;*/
function urlArgs(){
var args = {};
var query = location.search.substring(1);//查找到查询串,去掉?
var pairs = query.split('&');//根据“&”符合将查询字符部分分隔开
for(var i=0;i<pairs.length;i++){
var pos = pairs[i].indexOf('=');//"查找name=value"
if(pos == -1) continue;//如果没有找到的话就跳过
var name = pairs[i].substring(0,pos);//提取name
var value = pairs[i].substring(pos+1);//提取value
args[name] = value;
}
return args;
}
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
//alert(url);
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
}
}
return theRequest;
}
</script>
</body>
</html>