<分区>
在 JavaScript 中使用什么可以提高性能?
document.children[0].children[1]
对比
document.querySelector('body')
哪个性能更快?
<分区>
在 JavaScript 中使用什么可以提高性能?
document.children[0].children[1]
对比
document.querySelector('body')
哪个性能更快?
最佳答案
这里是从快到慢的结果:
document.body
(到目前为止)document.querySelector('body')
, document.children[0].children[1]
, document.getElementsByTagName('body')[ 0]
(差不多)document.querySelectorAll("body")[0]
, $('body')
来源JSBench (自己试试)
关于javascript - 哪种方法选择正文元素更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34745048/