本文介绍了jQuery empty()与remove()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jQuery
中的empty()
和remove()
方法之间有什么区别,当我们调用这些方法中的任何一个时,正在创建的对象将被销毁并释放内存?
What's the difference between empty()
and remove()
methods in jQuery
, and when we call any of these methods, the objects being created will be destroyed and memory released?
推荐答案
-
empty()
将删除所选内容的所有内容. -
remove()
将删除所选内容及其内容. empty()
will remove all the contents of the selection.remove()
will remove the selection and its contents.
考虑:
<div>
<p><strong>foo</strong></p>
</div>
$('p').empty(); // --> "<div><p></p></div>"
// whereas,
$('p').remove(); // --> "<div></div>"
它们都是删除DOM对象,应该释放它们占用的内存,是的.
Both of them remove the DOM objects and should release the memory they take up, yes.
这篇关于jQuery empty()与remove()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!