function getUrlParams(name) { var url = window.location.search; if (url.indexOf('?') == 1) { return false; } url = url.substr(1); url = url.split('&'); var name = name || ''; var nameres; for (var i = 0; i < url.length; i++) { var info = url[i].split('='); var obj = {}; obj[info[0]] = decodeURI(info[1]); url[i] = obj; } if (name) { for (var i = 0; i < url.length; i++) { for (const key in url[i]) { if (key == name) { nameres = url[i][key]; } } } } else { nameres = url; } return nameres; }
调用: let ifCoupon = getUrlParams("ifCoupon")