闭包的内存泄漏解决办法
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>sss</title> </head> <body> <div desc="hhhh">在线学习</div> <div desc="xxxx">开源产品</div> <script type="text/javascript"> let divs = document.querySelectorAll("div"); divs.forEach(function(item){ let desc = item.getAttribute("desc"); item.addEventListener("click",function(){ console.log(desc); console.log(item); }); item = null; }); </script> </body> </html>