方法一:
//取url参数 var type = request("type")
function request() {
var query = location.search;
var paras = arguments[0];
if (arguments.length == 2) {
query = arguments[1];
}
if (query != "") {
if (query.indexOf("?") != -1) {
query = query.split("?")[1];
}
query = query.split("&");
for (var i = 0; i < query.length; i++) {
var querycoll = query[i].split("=");
if (querycoll.length == 2) {
if (querycoll[0].toUpperCase() == paras.toUpperCase()) {
return querycoll[1];
break;
}
}
}
}
return "";
} //调用方法 var mid=request("mid");
方法二:正则法
function request(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// 这样调用:
alert(request("mid"));