Javascript 拆分窗口位置URL并使用数据属性值连接并刷新页面
希望从数据键获取值并与.html连接。按照逻辑完成,但未附加到windows url中 初始Url将为- 根据键值(Ex:25888)收集需要在url内追加如下内容 谢谢Javascript 拆分窗口位置URL并使用数据属性值连接并刷新页面,javascript,Javascript,希望从数据键获取值并与.html连接。按照逻辑完成,但未附加到windows url中 初始Url将为- 根据键值(Ex:25888)收集需要在url内追加如下内容 谢谢 $('a.dropdown-item')。在('click',function()上{ 让getDataKey=$(this.attr('data-key'); 让getWindowLocation=location.pathname.split('/')[1]; 让getLocationVal=getWindowLocat
$('a.dropdown-item')。在('click',function()上{
让getDataKey=$(this.attr('data-key');
让getWindowLocation=location.pathname.split('/')[1];
让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
});
试试这个
$('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
});