jQuery:如果使用html()从DOM中删除事件处理程序,则从对象中删除它们 [英] jQuery : Are events handlers removed from objects if they are removed from the DOM using html()
问题描述
我已经搜索过jquery文档没有明确的答案。有人知道吗?
谢谢你们!
如果您使用jQuerys .html()
,它将会照顾您。查看jQuery源代码,该行被调用:
jQuery.cleanData(this [i] .getElementsByTagName(* ));
它有效地清理了所有的数据和事件。如果您重新覆盖DOMnodes innerHTML
属性,这当然不起作用。
I am concerned about memory leaks in my application as I use jquery's html() method a lot to replace content in the the DOM. I just want to make sure that not of these event listeners are going to be hanging around in browser memory.
I have searched the jquery docs with no clear answer. Does anyone know?
Thanks guys!
Yes they are.
If you use jQuerys .html()
it will take care of you. Looking into the jQuery source, this line is getting called:
jQuery.cleanData( this[i].getElementsByTagName("*") );
which effectively cleans up all data and events. This of course won't work if you're overwritting a DOMnodes innerHTML
property explicitly.
这篇关于jQuery:如果使用html()从DOM中删除事件处理程序,则从对象中删除它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!