Created
January 29, 2018 06:37
-
-
Save mrxf/f8e5261ec3ba40f4eb52cb3dcb7f8d12 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
/** | |
* 根据参数名获取参数值 | |
* @param {string} name 参数名 | |
* @param {string} [url] 地址 | |
*/ | |
function getParameterByName(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} |
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
/** | |
* 获取页面hash值 | |
*/ | |
function getHash() { | |
let hash = window.location.hash.split("?") | |
return hash[0].substr(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment