参考答案:
1 2const box = document.getElementById('box'); 3 4function isIcon(target) { 5 return target.className.includes('icon'); 6} 7 8box.onclick = function(e) { 9 e.stopPropagation(); 10 const target = e.target; 11 if (isIcon(target)) { 12 target.style.border = '1px solid red'; 13 } 14} 15 16const doc = document; 17 18doc.onclick = function(e) { 19 const children = box.children; 20 for(let i = 0; i < children.length; i++) { 21 if (isIcon(children[i])) { 22 children[i].style.border = 'none'; 23 } 24 } 25}
最近更新时间:2022-10-30