Fork me on GitHub

通过window.location.search获取页面url传递的参数

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = decodeURI(window.location.search.substr(1)).match(reg);
    if (r != null)return unescape(r[2]);
    return null;
}

var sname = GetQueryString("name");
if(sname!=null){
    var sname_ = decodeURIComponent(sname); 
    alert(sname_);
}      

例如:
abcd.html?name=xyz
获取的值xyz

posted @ 2017-06-08 00:57  fozero  阅读(6048)  评论(0编辑  收藏  举报