Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拆分窗口位置URL并使用数据属性值连接并刷新页面_Javascript - Fatal编程技术网

Javascript 拆分窗口位置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

希望从数据键获取值并与.html连接。按照逻辑完成,但未附加到windows url中

初始Url将为-

根据键值(Ex:25888)收集需要在url内追加如下内容

谢谢

$('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

  });