代码改变世界

获取url中的参数

2018-06-13 11:46  不痒不痛  阅读(449)  评论(0编辑  收藏  举报

url地址

http://localhost:8080/xx/xx.htm?columnName=测试&columnId=2c908095636c27e601636cb335550006

  注意:如果url中有中文,先提前用codeURI转码

获取url项目路径

var curPath=window.document.location.href;
var localhostPath=curPath.substring(0,curPath.lastIndexOf("/")+1);

  参考地址:http://www.cnblogs.com/l412382979/p/8574813.html

获取url中的参数

function getRequest(){
	var strs;
     //将url再次进行解码,这样中文就不会出现乱码了 var url=decodeURI(location.search); var theRequest=new Object(); if(url.indexOf("?")!=-1){ var str=url.substr(1); strs=str.split("&"); for(var i=0;i<strs.length;i++){ theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); } return theRequest; } }

  使用方法

var req=getRequest();
alert(req["columnName"]);