Home >php教程 >php手册 >JS仿PHP$_GET获取get参数

JS仿PHP$_GET获取get参数

WBOY
WBOYOriginal
2016-06-06 20:10:22899browse

var $_GET = (function(){var url = window.document.location.href.toString();var u = url.split("?");if(typeof(u[1]) == "string"){u = u[1].split("var get = {};for(var i in u){var j = u[i].split("=");get[j[0]] = j[1];}return get;} else {return

var $_GET = (function(){
	var url = window.document.location.href.toString();
	var u = url.split("?");
	if(typeof(u[1]) == "string"){
		u = u[1].split("&");
		var get = {};
		for(var i in u){
			var j = u[i].split("=");
			get[j[0]] = j[1];
		}
		return get;
	} else {
		return {};
	}
})();

/*使用时, 可以直接 $_GET['get参数'], 就直接获得GET参数的值*/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn