创建/添加节点VS的innerHTML [英] create/append node vs innerHTML

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

问题描述

有没有人有一个很好的理由使用了另一种?至于我可以告诉大家,创建/追加节点只是从创建无效code prevents你,而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 是从标准的角度有点可疑的由来。我觉得怪异模式的文章仍然是相关的,但我很乐意看到它进行更新。也许联系人 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.

  • DOM DocumentFragments
  • jQuery Performance Rules
  • Improve your jQuery - 25 excellent tips
  • Speed test: innerHTML versus DOM manipulation ... a test that actually tests the speed, worth it for anyone who wants to collect some current data on browsers

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆