📅  最后修改于: 2022-03-11 15:02:59.190000             🧑  作者: Mango
// Make a list
const ul = document.createElement('ul');
document.body.appendChild(ul);
const li1 = document.createElement('li');
const li2 = document.createElement('li');
ul.appendChild(li1);
ul.appendChild(li2);
function hide(evt) {
// e.target refers to the clicked element
// This is different than e.currentTarget, which would refer to the parent in this context
evt.target.style.visibility = 'hidden';
}
// Attach the listener to the list
// It will fire when each - is clicked
ul.addEventListener('click', hide, false);