gpt4 book ai didi

jquery - 我想使用 jquery 更改语言 url

转载 作者:行者123 更新时间:2023-12-01 05:14:48 25 4
gpt4 key购买 nike

我想使用 jquery 更改语言 URL。我的网址是https://beta.yourtaxi.ch/de_DE/about-us/并想改变它只是 https://beta.yourtaxi.ch/en_Us/about-us/ 。我已经尝试过下面的代码但不起作用。

$('a[rel="group"]').on('click', function(e) {
e.preventDefault();
location.href = $(this).data('wpurl');
$(this).attr('href', wpurl);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sidebar_lang">
<span>Language:</span>
<div class="lang_option">
<a href="<?php echo site_url(); ?>/en_Us/" data-wpurl="<?php echo site_url(); ?>/de_DE/" class="lang_txt" rel="group">DE</a>
<a href="<?php echo site_url(); ?>/de_DE/" data-wpurl="<?php echo site_url(); ?>/en_Us/" class="lang_txt" rel="group">EN</a>
</div>
</div>

最佳答案

您可以获取当前路径,然后删除第一部分以附加到 <a> 中的 URL。标签。

例如

const appendPath = location.pathname // current full path, eg "/de_DE/about-us/"
.split('/') // split on "/" -> ["", "de_DE", "about-us", ""]
.slice(2) // omit the first two parts -> ["about-us", ""]
.join('/') // join in to a slash-delimited string -> "about-us/"

location.href = $(this).data('wpurl') + appendPath

关于jquery - 我想使用 jquery 更改语言 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50617452/

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