本文介绍了创建/附加节点与innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有充分的理由使用一个而不是另一个?据我所知,创建/追加节点只是防止您创建无效代码,而 innerHTML 允许您一次注入多个节点.

Does anyone have a good reason to use one over the other? As far as I can tell, create/append node simply prevents you from creating invalid code, while innerHTML allows you to inject multiple nodes at once.

鉴于我需要插入多个标签,使用innerHTML 似乎很有意义.有人有不同的看法吗?

Given that I need to insert several tags, it seems to make sense to use innerHTML. Does anyone have a different take?

推荐答案

这总是一个有争议的论点,部分原因是 innerHTML 的起源从标准的角度来看有些可疑.我认为 QuirksMode 文章仍然相关,但我很想看到它更新.也许 contact ppk 关于更新它们,尽管我确定他很忙.我们都可以从我们在 Web 开发中所做的假设的性能测试中受益.说到底还是需要硬数据来证明,不然真的只是说说而已.

This is always a contentious argument, partially because the origin of innerHTML being somewhat dubious from a standards perspective. I think the QuirksMode article is still relevant, but I'd love to see it updated. Perhaps contact ppk about updating them, though I'm sure he's busy. We could all benefit from performance testing the assumptions we make in web development. In the end claims require hard data to prove, otherwise it's really just talk.

无论如何,我进行了一些搜索并找到了一些与此讨论相关的有趣文章.我不记得以前听说过 DocumentFragments,它们真的很有趣.

Anyway, I did some searching and found some interesting articles relevant to this discussion. I don't remember hearing of DocumentFragments before, they're real interesting.

这篇关于创建/附加节点与innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:02