Skip to content

Instantly share code, notes, and snippets.

@cubika
Created January 26, 2016 09:59
Show Gist options
  • Select an option

  • Save cubika/8556c1313e953a11ecac to your computer and use it in GitHub Desktop.

Select an option

Save cubika/8556c1313e953a11ecac to your computer and use it in GitHub Desktop.
getQueryString
function getQueryString(url, name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var index = url.indexOf('?');
var r = url.substr(index).substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
var context = '';
if (r != null)
context = r[2];
reg = null;
r = null;
return context == null || context == '' || context == 'undefined' ? '' : context;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment