gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:05:33 24 4
gpt4 key购买 nike

想要从 data-key 获取值并与 .html 结合。完成以下逻辑,但它没有附加到 Windows url 中。

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

根据收集的键值(例如:258888)需要附加内部网址,如 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

});

关于javascript - 拆分窗口位置 URL 并与数据属性值 JOIN 并刷新​​页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60646754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com