<ul id="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
let ul = document.querySelector('#list');
ul.addEventListener('click', function(e){
let target = e.target;
while( target.tagName !== 'LI' ){
if ( target.tagName === 'UL' ){
target = null;
break;
}
target = target.parentNode;
}
if ( target ){
console.log('你点击了ui里的li')
}
})
网友评论