我更新了codepan js代码。请使用下面的js代码激活选项卡。我已经测试过了,效果很好。如果这对你有用,请告诉我!
class TabList {
constructor(buttonsContainer, tabs) {
this.buttonsContainer = buttonsContainer;
this.tabs = tabs;
this.buttonsContainer.addEventListener("click", event => {
document.querySelector( \'.woocommerce-tabs__button--active\' ).classList.remove( \'woocommerce-tabs__button--active\' );
event.target.closest(".woocommerce-tabs__button").classList.add("woocommerce-tabs__button--active");
const index = event.target.closest(".woocommerce-tabs__button").dataset
.value;
this.openTab(index);
});
}
openTab(index) {
this.tabs.querySelector(".active").classList.remove("active");
this.tabs
.querySelector(`.woocommerce-tabs__content--${index}`)
.classList.add("active");
}
}
document.addEventListener("DOMContentLoaded", () => {
const buttonsContainer = document.querySelector(".woocommerce-tabs__buttons");
const tabs = document.querySelector(".woocommerce-tabs__contents");
const tabList = new TabList(buttonsContainer, tabs);
});