单击 Tab 时替换 window
When Tab is clicked replace window
我正在尝试为网站做一个语言切换器,我正在使用一个带有 2 个选项卡的选项卡元素 -
现在我正在尝试在单击其中一个选项卡时对 url 执行 window.location.replace。
所以选项卡 1 应该 link 到 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>
<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);
if (index == 1) {window.open('google.de', '_self');}
else if (index == 2) {window.open('google.com', '_self');}
else {//open default window}
});
</script>
我正在尝试为网站做一个语言切换器,我正在使用一个带有 2 个选项卡的选项卡元素 -
现在我正在尝试在单击其中一个选项卡时对 url 执行 window.location.replace。
所以选项卡 1 应该 link 到 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>
<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);
if (index == 1) {window.open('google.de', '_self');}
else if (index == 2) {window.open('google.com', '_self');}
else {//open default window}
});
</script>