1、获取链接全部参数,以对象的形式返回
//获取url中参数 function GetRequest() { var url = location.search; //获取url中"?"符后的字串 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]); } } }
2、根据参数名获取链接中的参数值
function GetRequest2(key) { var url = 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]); } } var value = theRequest[key]; return value; }
原文地址:https://www.cnblogs.com/dyhao/p/9923574.html
时间: 2024-11-04 17:44:31