方法1:
function getRequest(strParame) { var args = new Object(); var query = location.search.substring(1); var pairs = query.split("&"); // Break at ampersand for (var i = 0; i < pairs.length; i++) { var pos = pairs[i].indexOf('='); if (pos == -1) continue; var argname = pairs[i].substring(0, pos); var value = pairs[i].substring(pos + 1); value = decodeURIComponent(value); args[argname] = value; } return args[strParame]; }
调用方法:var id=getRequest("id");
方法2
//获取url参数--摘自 we7CMS/Script/Common.js var Request = { parameter: function(name) { return this.parameters()[name]; }, parameters: function() { var result = {}; var url = window.location.href; var parameters = url.slice(url.indexOf('?') + 1).split('&'); for (var i = 0; i < parameters.length; i++) { //var parameter = parameters[i].split('='); var index = parameters[i].indexOf("="); var name = parameters[i].slice(0, index); var value = parameters[i].slice(index + 1, parameters[i].length + 1); result[name]= value; } return result; } }
调用方法:
var folder = Request.parameter("folder");
方法3 摘自extjs-4.1.1/examples/shared/include-theme.js
function getQueryParam(name) { var regex = RegExp('[?&]' + name + '=([^&]*)'); var match = regex.exec(location.search) || regex.exec(path); return match && decodeURIComponent(match[1]); }
调用方法:
var id = getQueryParam("name");