javascript接收get方式提交的参数
2009-02-21 09:43 Iron 阅读(337) 评论(0) 编辑 收藏 举报function JsQueryString(key)
{
if (window.location.search!="")
{
var urlprmlist=new Array();
urlprmlist=window.location.search.split("&");
urlprmlist[0]=urlprmlist[0].substr(1);
for(i=0;i<urlprmlist.length;i++)
{
key2=key;
keyname=urlprmlist[i].split("=");
keyname[0]="|"+keyname[0].toUpperCase()+"|";
key2="|"+key2.toUpperCase()+"|";
if(keyname[0].indexOf(key2)!=-1)
{
return trim(keyname[1]);
}
}
}
function ltrim(s){
return s.replace( /^\"*/, "");
}
function rtrim(s){
return s.replace( /\"*$/, "");
}
function trim(s){
return rtrim(ltrim(s));
}
}
//替换href中的get参数,myhref地址,parmvar参数名,reparmvalue新参值
function GetparmRP(myhref,parmvar,reparmvalue)
{
var re = new RegExp(parmvar+'=([^&]*)')
if(myhref.search(/\?/)==-1)
{
myhref=myhref+'?'+parmvar+'='+reparmvalue;
return myhref;
}
if(myhref.search(re)==-1)
{
myhref=myhref+'&'+parmvar+'='+reparmvalue;
return myhref;
}
myhref=myhref.replace(re,parmvar+'='+reparmvalue);
return myhref;
}
感谢:http://blog.csdn.net/fmpfantasy/archive/2008/04/27/2335539.aspx