获取连接后面的参数

工作中总会遇到别人传过来的数据,尤其是在连接当中的。

所以记录下获取连接参数的方法

function getUrlParam(name) {

  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象

  // var r = urlHerf.substr(1).match(reg); //匹配目标参数

  var r = window.location.search.substr(1).match(reg); //匹配目标参数

  if (r != null) return unescape(r[2]);

  return ""; //返回参数值

}

你可能感兴趣的:(获取连接后面的参数)