Skip to content

Instantly share code, notes, and snippets.

@mrxf
Created January 29, 2018 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrxf/f8e5261ec3ba40f4eb52cb3dcb7f8d12 to your computer and use it in GitHub Desktop.
Save mrxf/f8e5261ec3ba40f4eb52cb3dcb7f8d12 to your computer and use it in GitHub Desktop.
url操作
/**
* 根据参数名获取参数值
* @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, " "));
}
/**
* 获取页面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