【发布时间】:2021-10-16 13:46:29
【问题描述】:
我正在尝试为网站做一个语言切换器,我正在使用带有 2 个选项卡的选项卡元素 -
现在我正在尝试在单击其中一个选项卡时对 url 执行 window.location.replace。
所以标签 1 应该链接到 google.de,标签 2 应该链接到 google.com
我不太清楚如何定义每个标签
这就是我得到的当前代码
<script>
// when DOM ready
$(document).ready(function() {
// if 'tab' item exists in localStorage
if(localStorage.getItem('tab')){
// click the respective tab button
// e.g. if 'tab' item value == 0
// click tab[0]
$('.tab-button')[localStorage.getItem('tab')].click();
}
});
// on tab click
$('.tab-button').click(function(){
// get its index
const index = $('.tab-button').index(this);
// store the index in localStorage
localStorage.setItem('tab',index);
});
</script>
【问题讨论】:
-
请添加相关html
标签: javascript html webflow