Storing php $_GET variable in a javascript variabl

2020-02-11 07:46发布

I am passing two pieces of info to a php page using the $_GET method (team1, team2). I'd like to use these as variables in some javascript. How can I do this?

Thanks

7条回答
forever°为你锁心
2楼-- · 2020-02-11 08:17

Since $_GET just access variables in the querystring, you can do the same from javascript if you wish:

<script>
var $_GET = populateGet();

function populateGet() {
  var obj = {}, params = location.search.slice(1).split('&');
  for(var i=0,len=params.length;i<len;i++) {
    var keyVal = params[i].split('=');
    obj[decodeURIComponent(keyVal[0])] = decodeURIComponent(keyVal[1]);
  }
  return obj;
}
</script>
查看更多
登录 后发表回答