js获取当前url参数

 1 //抓取url参数
 2         function GetRequest() {
 3             var url = location.search; //获取url中"?"符后的字串
 4             var theRequest = new Object();
 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]] = unescape(strs[i].split("=")[1]);
10                 }
11             }
12             return theRequest;
13         }

调用:

 var Request = new Object();
            Request = GetRequest();
            var ip = Request['serverip']; //serverip相当于test.com/index.aspx?serverip=127.1.1.1

 

posted @ 2015-05-18 14:29  许大虾  阅读(281)  评论(0编辑  收藏  举报