在DOM中添加/删除多个元素的最快方法 [英] Fastest way to add/remove multiple elements in DOM

查看:288
本文介绍了在DOM中添加/删除多个元素的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:它不是最快的DOM插入的重复,因为它也包括事件监听器变量。无论如何,我会编辑这个问题。

如果有人已经发现,我会知道一些事情。

I would to know some things if someone already discovered.

我想知道哪个是在javascript中添加元素并与ie6 +,chrome10 +,firefox2 +兼容的最快方法。

I would like to know which is the fastest way to add an element in javascript and to be compatible with ie6+, chrome10+, firefox2+.

最快的技术:

Fastest technique to:


  1. 添加单个元素

  2. 添加100个元素

  3. 添加1个元素或1000个元素的任何时间曲线

  1. Add a single element
  2. Add 100 elements
  3. Any time curve for adding 1 element or 1000 elements

与上述相同但用于删除元素

The same as above but for removing an element

添加/更改/删除内联样式属性

Add/Change/Remove an inline style attribute

添加事件监听器,如mousedown / mouseup / mouseover

Add event listeners like mousedown/mouseup/mouseover

比其他人添加/删除某些标签更快吗?例如:添加/删除< div> < p> 更快? (在添加模式中:我认为是更快的< p> ,因为它只有1个字母与3个字母,也许是因为div是一个容器,我不知道,这就是为什么我问:D)

Is faster to add/remove some tags over others? ex: is faster to add/remove a <div> or a <p>? (In the adding mode: I think is faster <p> because it only has 1 letter vs 3 letters, and maybe because div is a container. I don't know, that's why I'm asking :D)


  1. 删除一个元素,以某种方式保存到js中,然后重新添加并保留事件在删除元素之前工作的监听器


问题,所以如果你只知道一些问题,你可以随时分享你所认识的东西;)

谢谢谢谢!

推荐答案

1 将父元素上的 innerHTML 的值设置为包含新元素的HTML的字符串。

2 相同于1.

4 将父元素上的 innerHTML 的值设置为空字符串。

7.1 调用 Node.removeChild(),保存返回的Node对象,然后将节点传递给 Node.appendChild()

1   Set the value of innerHTML on the parent element to a string containing HTML for the new elements.
2   Same as 1.
4   Set the value of innerHTML on the parent element to an empty string.
7.1   Call Node.removeChild(), save the returned Node object, and then pass the node to Node.appendChild().

这篇关于在DOM中添加/删除多个元素的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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