📜  addEventListener 仅调用一次 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:24.130000             🧑  作者: Mango

代码示例1
var list = document.getElementsByTagName('ul')[0]

list.addEventListener('click', function(e){
  var el = e.target
  // walk up the tree until we find a LI item
  while (el && el.tagName !== 'LI') {
     el = el.parentNode
  }
  console.log('item clicked', el)
},{ once: true }) // when we use once as true, it will never call again