js获取地址栏get参数

//获取url中get参数的值
function getQuery(name){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    if('undefined' != vars[name]){
    	return vars[name];
    }else{
    	return '';
    }
}
//获取url中"?"符后的字串
function getQueryString() {
	var url = location.search;
	var str="";
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
	}
	return str;
}

 

发表评论

电子邮件地址不会被公开。

*