[英]JavaScript style.display=“none” or jQuery .hide() is more efficient?
document.getElementById("elementId").style.display="none"
is used in JavaScript to hide an element. 用于在JavaScript中隐藏元素。 But in jQuery,
但在jQuery中,
$("#elementId").hide();
is used for the same purpose. 用于相同的目的。 Which way is more efficient?
哪种方式更有效? I have seen a comparison between two jQuery function
.hide()
and .css("display","none")
here . 我已经看到了两个jQuery函数之间的比较
.hide()
和.css("display","none")
在这里 。
But my problem is whether pure JavaScript is more efficient than jQuery? 但我的问题是纯JavaScript是否比jQuery更有效?
Talking about efficiency: 谈论效率:
document.getElementById( 'elemtId' ).style.display = 'none';
What jQuery does with its .show()
and .hide()
methods is, that it remembers the last state of an element. 什么jQuery不会与它
.show()
和.hide()
方法是,它记住元素的最后状态 。 That can come in handy sometimes, but since you asked about efficiency that doesn't matter here. 这有时会派上用场,但是因为你问的效率在这里并不重要。
Efficiency isn't going to matter for something like this in 99.999999% of situations. 在99.999999%的情况下,效率对于这样的事情并不重要。 Do whatever is easier to read and or maintain.
做任何更容易阅读和维护的事情。
In my apps I usually rely on classes to provide hiding and showing, for example .addClass('isHidden')/.removeClass('isHidden')
which would allow me to animate things with CSS3 if I wanted to. 在我的应用程序中,我通常依赖类来提供隐藏和显示,例如
.addClass('isHidden')/.removeClass('isHidden')
,如果我愿意,它可以让我用CSS3动画。 It provides more flexibility. 它提供更多的灵活性。
a = 2;
vs VS
a(2);
function a(nb) {
lot;
of = cross;
browser();
return handling(nb);
}
In your opinion, what do you think is going to be the fastest? 在您看来,您认为最快的是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.