1 // 获取url中的参数,并返回一个对象
2 $.getRequestData = function() {
3 var url = location.search; //获取url中"?"符后的字串
4 var theRequest = {};
5 if (url.indexOf("?") != -1) {
6 var str = url.substr(1);
7 strs = str.split("&");
8 for (var i = 0; i < strs.length; i++) {
9 theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
10 }
11 }
12 return theRequest;
13 };
14
15 // 生成一个带参数的url
16 $.createUrl = function(obj) {
17 var length = obj && obj.length,
18 idx = 0,
19 url = obj.url + '?';
20 for (var key in obj) {
21 if (key != 'url' && obj[key] !== null) {
22 url += (key + '=' + encodeURIComponent(obj[key]) + '&');
23 }
24 }
25 return url.substring(0, url.lastIndexOf('&'));
26 }