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