地址栏获取url参数及在url后添加参数
function updateQueryStringParameter(uri, key, value) {
if (!value) {
return uri;
}
let re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
let separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
} else {
return uri + separator + key + "=" + value;
}
}
function Request(m) {
let sValue = location.search.match(
new RegExp("[?&]" + m + "=([^&]*)(&?)", "i"));
return sValue ? sValue[1] : sValue;
amend()
}
function amend(ind) {
let newurl = updateQueryStringParameter(window.location.href, 'anchor', 'giftbag' + ind);
window.history.replaceState({
path: newurl
}, '', newurl);
}
if (Request('anchor')) {
const config = $(nodeWrap).find('[data-coupon-option]').data('coupon-option');
let key = Request('anchor').slice(0, Request('anchor').length - 1);
let currentDom = $(nodeWrap).find("#giftbag").attr("id");
if (key == currentDom) {
let scrollInd = Request('anchor').replace(/[^0-9]/ig, "") - 1;
$('.cardBox', nodeWrap).eq(scrollInd).addClass('active').siblings().removeClass('active');
$('.J_firstLevel').removeClass('active')
$('.J_firstLevel').eq(scrollInd).addClass('active');
setTimeout(function() {
let aboveTop = $(nodeWrap).find("#giftbag").offset().top - 50;
$("html, body").animate({
scrollTop: aboveTop
}, 400);
}, 500);
}
}
amend(Request('anchor').replace(/[^0-9]/ig, ""));