拆分窗口位置URL并与数据属性值JOIN并刷新页面



想要从数据键中获取值并与.html连接。完成以下逻辑,但不附加在windows url中。

初始Url将为-http://www.test.com/en/location/london.html

根据收集到的键值(Ex:258888(,需要在url中添加http://www.test.com/en/location/london.258888.html

感谢

$('a.dropdown-item').on('click', function(){
let getDataKey = $(this).attr('data-key');
let getWindowLocation = location.pathname.split('/')[1];
let getLocationVal = getWindowLocation.split('.');
getLocationVal.join(getDataKey);
});

试试这个。

$('a.dropdown-item').on('click', function(){
let getDataKey = $(this).attr('data-key');
let getWindowLocation = window.location.href;
let getLocationVal = getWindowLocation.replace(/.html/, "." + getDataKey + ".html");
console.log(getLocationVal);
window.location.replace(getLocationVal); //To redirect to the new url
});

最新更新