75年生人,程序员,在西安。

jQuery中使用.remove和.detach的区别

The .detach() method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

.detach()方法与.remove()方法很类似,但.detach()方法会保留所有删除元素的jQuery数据关联关系。这个方法在删除元素后又在稍后要加回到页面时会非常有用。

今天遇到个bug,是因为移除了某元素,而再render回去时很多按钮事件无效了,原来是因为使用了.remove()方法,而改用.detach()方法后就正常了。


评论

© 世风十三 | Powered by LOFTER