js - get-the-value-from-the-url-parameter(可以在非模态对话框中使用)

  ref: http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-url-parameter

  函数:

function getQueryParams(qs) {
    qs = qs.split("+").join(" ");

    var params = {}, tokens,
        re = /[?&]?([^=]+)=([^&]*)/g;

    while (tokens = re.exec(qs)) {
        params[decodeURIComponent(tokens[1])]
            = decodeURIComponent(tokens[2]);
    }

    return params;
}

然后可以通过这样方式访问:  
  //var query = getQueryParams(document.location.search);
  //alert(query.foo);

posted @ 2015-05-01 10:02  wonkju  阅读(284)  评论(0编辑  收藏  举报