将一个URL的get变量放入变量中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将一个URL的get变量放入变量中相关的知识,希望对你有一定的参考价值。
/* * Allow to get into associative array, the GET variable of one URL * * USING: * To get all the variable of one URL * var a = getUrlVars('http://domaine.tld/index.php?me=beauGosse&Robert=Moche')["me"]; * return {"me" : "beauGosse", "Robert" : "Moche"} * * To get a value of first parameter you would do this: * var f = getUrlVars('http://domaine.tld/index.php?me=beauGosse&Robert=Moche')["me"]; * return beauGosse * * To get the second parameter * var s = getUrlVars('http://stan.com/index.php?me=beauGosse&Robert=Moche')["Robert"]; * return Moche * * INSPIRATION: * http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html */ function getVarsGet(url) { var vars = {}, hash; var hashes = url.slice(url.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars[hash[0]] = hash[1]; } return vars; }
以上是关于将一个URL的get变量放入变量中的主要内容,如果未能解决你的问题,请参考以下文章
PHP - 将变量放入 url 时,include() 文件不起作用?