jquery,性能方面什么是更快的getElementById或jquery选择器? [英] jquery, performance-wise what is faster getElementById or jquery selector?

查看:164
本文介绍了jquery,性能方面什么是更快的getElementById或jquery选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从性能方面做得更好 document.getElementById('elementId') $('#elementId')
如何自己计算速度?

解决方案

如果你担心性能问题,原生的getElementById就多了更快,但jQuery为您提供了非常方便的访问许多东西。所以,你可能想要使用类似的东西:

  $(document.getElementById(some_id))。jQueryCall(); 

这将为您提供更好的性能,同时允许您使用jQuery。 / p>

What is better from performance wise document.getElementById('elementId') or $('#elementId') ? How can I calculate the speed by myself?

解决方案

If you are concerned about performance, native getElementById is much much faster, but jQuery gives you very handy access to a lot of stuff. So, you might want to use something like :

$( document.getElementById("some_id") ).jQueryCall();

This will give you a better performance, and at the same time, allow you to use jQuery.

这篇关于jquery,性能方面什么是更快的getElementById或jquery选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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