自从我开始使用 JQuery 和 js 以来,这个问题就一直困扰着我,
如果 ad 将事件添加到 div。让我们说
$('#myid').click(function(){alert('ho user ')} )
然后我从 dom 中删除该 div。
$('#myid').remove()
如果我不解绑事件,会有内存惩罚吗?
最佳答案
In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.
您可以使用它而不必担心内存泄漏,它是专门为确保没有内存泄漏而设计的。
关于javascript - 删除 div 会自动清除分配给绑定(bind)和其他元素的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19568216/