jQuery show()vs添加类 [英] jQuery show() vs adding Class
本文介绍了jQuery show()vs添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
其中哪些更有效(即更快):
Which of these is more efficient (i.e. faster):
$(elem).show();
或
$(elem).addClass(displayClass); // Where display class is "display: block;"
还是相同?
推荐答案
这取决于你之后,他们做不同的事情:
It depends what you're after, they do different things:
-
$(elem).show();
- 显示元素,从显示 jquery.com/hide />.hide()
或恢复元素的默认显示
类型 -
$(elem).addClass(displayClass);
- 添加一个类,
$(elem).show();
- shows the element, restoring thedisplay
from before.hide()
or restoring the defaultdisplay
for the element type$(elem).addClass(displayClass);
- adds a class, always with a certaindisplay
, not really restoring what was there - this is less flexible
这是更快吗? .addClass()
下来,您可以在这里测试,只需比花费更少的工作量 .show()
does 。然而,它不会做特定方面的,所以它的灵活性较低上述原因。
Which is faster? .addClass()
hands down, you can test it yourself here, it simply does a lot less work than .show()
does. However, it doesn't do as much feature-wise, so it's less flexible for the reasons above.
这篇关于jQuery show()vs添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文