javascript中获取地址栏参数

index.asp?id=xxx&name=xxx

方法一:

 <script>
function getvalue(name)
{
 var str=window.location.search;
 if (str.indexOf(name)!=-1)
 {
  var pos_start=str.indexOf(name)+name.length+1;
  var pos_end=str.indexOf("&",pos_start);
  if (pos_end==-1)
  {
   return str.substring(pos_start);
  }
  else
  {
   return str.substring(pos_start,pos_end)
  }
 }
 else
 {
  return "没有这个name值";
 }
}
var strName=prompt("请输入您所要值的名字");
alert(getvalue(strName));
</script>

方法二:

var URLParams = new Array();
var aParams = document.location.search.substr(1).split('&');
for (i=0; i < aParams.length  i++){
 var aParam = aParams.split('=');
 URLParams[aParam[0]] = aParam[1];
}

//取得传过来的name参数
name=URLParams["name"];

方法三:

<script type="text/javascript">
Request = {
 QueryString : function(item){
  var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
  return svalue ? svalue[1] : svalue;
 }
}
alert(Request.QueryString("id"));
</script>