📜  javascript .target - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:43.603000             🧑  作者: Mango

代码示例1
// 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);