码迷,mamicode.com
首页 > Web开发 > 详细

获取url中的参数

时间:2018-06-13 14:53:36      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:object   arch   doc   IV   The   string   col   解码   i++   

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"]);

  

获取url中的参数

标签:object   arch   doc   IV   The   string   col   解码   i++   

原文地址:https://www.cnblogs.com/l412382979/p/9176999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!