需要做到这一点,以便您只能从两个按钮中选择一个活动按钮。HTML
<button class="main__btn">uomo</button>
<button class="main__btn">donna</button>
JS
'use strict'
const mainBtn = document.querySelectorAll('.main__btn');
mainBtn.forEach(el => {
el.addEventListener('click', (event) => {
const target = event.currentTarget;
if(el.classList.contains('active')) {
el.classList.remove('active');
} else {
el.classList.add('active');
}
});
});
四季花海
qq_花开花谢_0
相关分类