Created
August 4, 2016 03:06
-
-
Save fengxuway/f555d6da02a2628581769c47c9a0456e to your computer and use it in GitHub Desktop.
获取URL的参数值
This file contains 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 getParam(name, url) { | |
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); | |
if (!url){ | |
url = window.location.href; | |
} | |
if(url.indexOf("?") <0){ | |
return null; | |
} | |
var query = url.substr(url.indexOf("?"), url.length); | |
var r = query.substr(1).match(reg); | |
if (r != null) | |
return decodeURI(r[2]); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment