Created
July 17, 2018 09:08
-
-
Save fhefh2015/a50c98f7e266aecfd9d75be44f76f8f1 to your computer and use it in GitHub Desktop.
获取URL参数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//正则方法 | |
function getQueryString(name) { | |
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); | |
var r = window.location.search.substr(1).match(reg); | |
if (r != null) { | |
return unescape(r[2]); | |
} | |
return null; | |
} | |
//拆分法 | |
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]); | |
} | |
} | |
return theRequest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment