1、通过传进来的参数名,用正则去匹配参数的值,并返回
function getQueryString(name) {
var reg =new RegExp("(^|&)"+ name +"=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r !=null) return unescape(r[2]); returnnull;
}
这样调用:alert(GetQueryString("参数名1"));
2、
function
GetRequest() {
var
url = location.search;
//获取url中"?"符后的字串
var
theRequest =
new
Object();
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]]=unescape(strs[i].split(
"="
)[1]);
}
}
return
theRequest;
}
这样调用:
var Request =new Object();
Request = GetRequest();
var 参数1 = Request['参数1'];
说明:以上两种方法来自博客园“jiekk”大神的,原文地址http://www.cnblogs.com/jiekk/archive/2011/06/28/2092444.html
3、此方法暂时还没验证过
var str=window.location.href;
//alert(str);
var es=/SouceID=/;
es.exec(str);
var right=RegExp.rightContext;
//alert(right);
4、
function GetParam(){
var url = document.location.href;
var name=""
if (url.indexOf("=")>0)
{
name = url.substring(url.indexOf("=")+1,url.length)
}
return name;
}
5、
function getParam(paramName)
{
paramValue = "";
isFound = false;
if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=")>1)
{
arrSource = unescape(this.location.search).substring(1,this.location.search.length).split("&");
i = 0;
while (i < arrSource.length && !isFound)
{
if (arrSource[i].indexOf("=") > 0)
{
if (arrSource[i].split("=")[0].toLowerCase()==paramName.toLowerCase())
{
paramValue = arrSource[i].split("=")[1];
isFound = true;
}
}
i++;
}
}
return paramValue;
}
6、
function Request(sName)
{
var sURL = new String(window.location);
var sURL = document.location.href;
var iQMark= sURL.lastIndexOf('?');
var iLensName=sName.length;
//retrieve loc. of sName
var iStart = sURL.indexOf('?' + sName +'=') //limitation 1
if (iStart==-1)
{//not found at start
iStart = sURL.indexOf('&' + sName +'=')//limitation 1
if (iStart==-1)
{//not found at end
return 0; //not found
}
}
iStart = iStart + + iLensName + 2;
var iTemp= sURL.indexOf('&',iStart); //next pair start
if (iTemp ==-1)
{//EOF
iTemp=sURL.length;
}
return sURL.slice(iStart,iTemp ) ;
sURL=null;//destroy String
}
说明:以上四个方法来自博客园“century”的,原文地址:http://www.blogjava.net/bainian/articles/185657.html
7、
function getarg()
{
var url = unescape(window.location.href);
var allargs = url.split("?")[1];
var args = allargs.split("&");
for(var i=0; i<args.length; i++)
{
var arg = args[i].split("=");
eval('this.'+arg[0]+'="'+arg[1]+'";');
}
}
这样调用:var urlarg=new getarg();var value= urlarg.cild;
此方法来自于程序员之窗,原文:http://www.csharpwin.com/dotnetspace/2772.shtml
暂时只收集到这些,希望对大家有用