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';
}
});
}
});
逻辑一样,感觉编译器还是有问题

京公网安备 11010502036488号