innerhtml 与 creatElement 的效率 2018/09/25 549 JS 背景 JS 在操作 dom 时,可以通过 createElement 创建 html 节点,然后 insert 或者 append 到 dom 中 JS 也可以通过 innerhtml, 直接将字符串的 html 节点放到 dom 中 性能 通过测试发现 innerhtml 的方式,效率高于 createElement,前者相当于直接赋值,后者则需要 create 后再 insert 对于大批量的 dom 操作,建议使用 innerhtml;单个 dom 的话,性能差异不明显。
Leave a Reply