js 获取地址栏中的参数

<script type="text/javascript" language="JavaScript">
//Function
function getQueryString(key) {
      var searchString = document.location.search.toString();
      var returnValue = '';
      if (searchString.substr(0, 1) == '?' && searchString.length > 1) {
         var queryString = searchString.substring(1, searchString.length)
         var queryList = queryString.split('&');
         for (var i = 0; i < queryList.length; i++) {
              var oneQuery = queryList[i].split('=');
              if (oneQuery[0] == key && oneQuery.length == 2) {
                  returnValue = oneQuery[1];
             }
        }
     }
     return returnValue;
}

 

//使用方法:
//例如:地址栏为http://www.baidu.com/a.html?a=123&b=456
function getValue()
{
  var aValue=getQueryString(a); 
  var bValue=getQueryString(b);
  alert(aValue);//123
  alert(bValue);//456
}
</script>

posted on 2012-06-26 17:29  wboweb  阅读(162)  评论(0编辑  收藏  举报

导航