function HTMLqueryString(strURL, strParam)
{
var strVal = ""; try
{
// if strURL = "http://www.mySite.com/myPage.htm?param1=val1¶m2=val2"
var nIndex = strURL.indexOf("?");
if (nIndex > 0)
{
// cut strURL into "¶m1=val1¶m2=val2"
strURL = "&" + strURL.substring(nIndex + 1, strURL.length);
nIndex = strURL.indexOf("&"+ strParam + "=");
if(nIndex >= 0)
{
// jump to the position after the equal sign, if we're looking for
// param1, then strURL should contain 'val1¶m2=val2'
strURL = strURL.substring(nIndex + strParam.length + 2, strURL.length); // in case there are other parameters followed
nIndex = strURL.indexOf("&");
if(nIndex == -1) //find the target
strVal = strURL;
else
strVal = strURL.substring(0, nIndex); // strVal should be 'val1' now
}
}
}
catch(e){} return strVal;
}
{
var strVal = ""; try
{
// if strURL = "http://www.mySite.com/myPage.htm?param1=val1¶m2=val2"
var nIndex = strURL.indexOf("?");
if (nIndex > 0)
{
// cut strURL into "¶m1=val1¶m2=val2"
strURL = "&" + strURL.substring(nIndex + 1, strURL.length);
nIndex = strURL.indexOf("&"+ strParam + "=");
if(nIndex >= 0)
{
// jump to the position after the equal sign, if we're looking for
// param1, then strURL should contain 'val1¶m2=val2'
strURL = strURL.substring(nIndex + strParam.length + 2, strURL.length); // in case there are other parameters followed
nIndex = strURL.indexOf("&");
if(nIndex == -1) //find the target
strVal = strURL;
else
strVal = strURL.substring(0, nIndex); // strVal should be 'val1' now
}
}
}
catch(e){} return strVal;
}
<script>
url = location;
ar = url.replace(/(.*)\?/g,"").split(/[&=]/);
for(i=0;i<ar.length;i+=2)
eval(ar[i]+"="+ ar[i+1]);
document.write(dd);
</script>
test.htm
<script>
url = location;
ar = url.replace(/(.*)\?/g,"").split(/[&=]/);
for(i=0;i<ar.length;i+=2)
eval(ar[i]+"="+ ar[i+1]);document.write(room);
document.write("<br/>");
document.write(id);
</script>在地址栏输入:test.htm?room=304&id=1"
var s = window.location.search; //得到 ?dd=dddddddd;
if(s)
{
var a = s.split("\?");
var b = a[1].split("%26");
for(var i=0; i<b.length; i++)
{
var c = b[i].split("=");
alert("你传入的变量 "+ c[0] +" 的值是 "+ c[1]);
}
}
</script>
alert(HTMLqueryString(location.href,"dd")),进行修改也行。谢谢!!!!