function HTMLqueryString(strURL, strParam)
{
var strVal = ""; try
{
// if strURL = "http://www.mySite.com/myPage.htm?param1=val1&param2=val2"
var nIndex = strURL.indexOf("?");
if (nIndex > 0)
{
// cut strURL into "&param1=val1&param2=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&param2=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;
}

解决方案 »

  1.   

    alert(HTMLqueryString(location.href,"dd"))
      

  2.   

    dd.html
    <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>
      

  3.   

    sorry!
    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"
      

  4.   

    <script language=javascript>
    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>
      

  5.   

    有没有一简单的方法,对了在 wsj(骆驼)回答的alert(HTMLqueryString(location.href,"dd")),运行时说缺少对象。问问大家,有没有简单的方式呢?或对这个
    alert(HTMLqueryString(location.href,"dd")),进行修改也行。谢谢!!!!