js获取url中的参数

function getQueryString(name) {//name为要提取的字段
    var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)" , "i");
    var r=window.location.search.substr(1).match(reg);
    if(r!=null)return decodeURI(r[2]);
    return null;
}

重温一下window.location系列:

window.location对象在编写时可不使用window这个前缀,例如:

  location.hostname 返回web主机的域名

  location.pathname 返回当前页面的路径和文件名

  location.port 返回web主机的端口

  location.protocol 返回所使用的web协议(http:// 或 https://)

  location.href 属性返回当前页面的完整URL

  location.assign() 方法加载新的文档 as:window.location.assign("http://www.w3school.com.cn")

参考链接:http://www.cnblogs.com/jiekk/archive/2011/06/28/2092444.html

原文地址:https://www.cnblogs.com/miaoying/p/6473798.html