题解 | #切换Tab栏目#
切换Tab栏目
https://www.nowcoder.com/practice/70916dc9292e470eb70ac2a0d3b9a404
options.onclick = function(e) {
optionItems.forEach((item, index) => {
if (e.target === item) {
item.style.backgroundColor = '#25bb9b';
items[index].style.display = 'block';
} else {
item.style.backgroundColor = '';
items[index].style.display = 'none';
}
})
}
options.addEventListener('click', function (e) {
if(e.target.nodeName === 'LI') {
optionItems.forEach(item => {
item.style.backgroundColor = '#fff';
});
e.target.style.backgroundColor = '#25bb9b';
items.forEach((item, index) => {
if(e.target.getAttribute('data-type') == index) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
}
});
逻辑一样,感觉编译器还是有问题