📌  相关文章
📜  TypeError:无法读取 null 的属性“addEventListener” - 无论代码示例

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

代码示例3
// Credit to: Rob M.
// Origin: https://stackoverflow.com/questions/26107125/cannot-read-property-addeventlistener-of-null

// I think the easiest approach would be to just 
// check that el is not null before adding an event listener:

var el = document.getElementById('overlayBtn');
if(el){
  el.addEventListener('click', swapper, false);
}