如何使用 JQuery 高效地附加内容 [英] how to efficiently append content with JQuery
本文介绍了如何使用 JQuery 高效地附加内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 JQuery 在标签内附加大量文本.我发现标签中当前的文本越多,附加越慢,而对于大量文本,它太慢了.
I am using JQuery to append large amounts of text inside a tag. I find the more text currently within the tag the slower appending is, and for large amounts of text it is too slow.
有没有更有效的方法来附加文本?例如创建虚拟子标签并设置它们的内容而不是附加到父标签?
Is there a more efficient way to append text? Such as for instance creating dummy child tags and setting the content of them rather than appending to the parent?
推荐答案
检查这个 presentation 还有这个:jQuery 反模式
总的来说:
Check this presentation and this one too: jQuery Anti-Patterns
And in general:
- 不要在循环中使用 .append()
- 不要直接追加到 DOM 中
- 构建一个字符串然后附加它或使用 DocumentFragment
- 不要直接追加到 DOM 中
这篇关于如何使用 JQuery 高效地附加内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文