事件的元素被破坏后会发生什么?据我所知,jQuery在其全局存储库"中仍具有该事件.就我而言,创建了许多元素,并绑定了一个事件并再次销毁了它们.
What happens to the event when its element was destroyed? As far as I know, jQuery still has the event in its global "repository". In my case, a lot of elements are created, bound with an event and destroyed again...
使用过多后是否需要害怕一些内存问题?
Do I need to be scared of some memory problems after excessive use?
推荐答案是.如果您有很多附加到html元素的事件处理程序,则应该显式删除它们(通过使用jQuery方法,例如remove或empty而不是例如detach或'regular'js),或更改事件的'binding ' 战略.我的意思是利用jQuery事件的委托.这样,您可以找到事件绑定元素集群的一些共同祖先,并将其绑定到事件.经验法则始终是尽量减少事件处理程序的数量.
Yes. If you have a lot of event handlers attached to html elements then you should either remove them explicitly (by using jQuery methods like remove or empty instead of eg detach or 'regular' js) or change your event 'binding' strategy. What I mean by that is taking advantage of jQuery's event's delegation. This way you can seek out some common ancestor to your cluster of event-binded-elements and binding it to the event instead. A rule of thumb is always to minimize the number of event handlers.
更多推荐
元素销毁后,事件会自动取消绑定吗?
发布评论