问题描述
我是实习生,我在标题中遇到了类似上面的代码。
I am an intern and I came across some code like the above in the title.
$(".someClass").removeClass('visible').addClass('invisible');
$(".someClass").removeClass('invisible').addClass('visible');
//there are css classes for this that set display to none etc.
它是越野车,我被指控改变一些UI的东西,所以我想我会用 .hide()
和替换上面的.show()
相应的。这些错误或多或少都消失了。一种方式比另一种方式有什么优势?在这种情况下,后者看起来效果更好,为什么你会以第一种方式实现呢?
It is buggy and I was charged with changing some UI stuff so I thought I would replace the above with .hide()
and .show()
correspondingly. The bugs have more or less disappeared. What are the advantages of one way over the other? In this case the latter appears to have worked better, so why would you implement it the first way?
我只是尝试显示和隐藏页面元素,具体取决于所选的页面选项。哪种选择是最佳做法?
I am just trying to show and hide page elements depending on what page options have been chosen. Which option is best practice?
推荐答案
$(selector).hide();
和
$(selector).show();
只需添加
style="display:none;"
和
style="display:block;"
分别为选择器。
你添加和删除类,你可以添加无数样式并在样式表中管理它们。
When you add and remove classes, you can add a myriad of styles and manage them in your style sheet.
就我个人而言,当我只是通过jQuery显示或隐藏选择器时,我使用
Personally, when I'm simply showing or hiding a selector via jQuery, I use
show();
hide();
或
toggle();
这篇关于.removeClass( '可见')addClass( '不可见'); vs. .hide()或.show()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!