是否有内置的方式来显示/隐藏jQuery中的元素?

时间:2022-12-02 18:09:44

I know how to show/hide, or fadeIn/out in jquery, but is there a built in way to toggle between show/hide or fadein/out or do I have first look if the element is display:none, if yes then show otherwise hide?

我知道如何在jquery中显示/隐藏或淡入/淡出,但有没有内置的方式在show / hide或fadein / out之间切换,或者我是否首先查看元素是否显示:none,if yes then show否则隐藏?

3 个解决方案

#1


14  

You could possibly use the toggle() function.

你可以使用toggle()函数。

http://docs.jquery.com/Effects/toggle

http://docs.jquery.com/Effects/toggle

or

要么

http://docs.jquery.com/Effects/slideToggle

http://docs.jquery.com/Effects/slideToggle

#2


0  

$(element).toggle()

Toggle displaying each of the set of matched elements. If they are shown, toggle makes them hidden (using the hide method). If they are hidden, toggle makes them shown (using the show method).

切换显示每组匹配的元素。如果显示它们,则切换会隐藏它们(使用隐藏方法)。如果它们被隐藏,则切换使它们显示(使用show方法)。

http://docs.jquery.com/Effects/toggle

http://docs.jquery.com/Effects/toggle

#3


0  

Check out the cycle plugin, it's great. Might not be exactly what you're looking for but it has some very nice features.

查看循环插件,这很棒。可能不是你想要的,但它有一些非常好的功能。

http://www.malsup.com/jquery/cycle/

http://www.malsup.com/jquery/cycle/

#1


14  

You could possibly use the toggle() function.

你可以使用toggle()函数。

http://docs.jquery.com/Effects/toggle

http://docs.jquery.com/Effects/toggle

or

要么

http://docs.jquery.com/Effects/slideToggle

http://docs.jquery.com/Effects/slideToggle

#2


0  

$(element).toggle()

Toggle displaying each of the set of matched elements. If they are shown, toggle makes them hidden (using the hide method). If they are hidden, toggle makes them shown (using the show method).

切换显示每组匹配的元素。如果显示它们,则切换会隐藏它们(使用隐藏方法)。如果它们被隐藏,则切换使它们显示(使用show方法)。

http://docs.jquery.com/Effects/toggle

http://docs.jquery.com/Effects/toggle

#3


0  

Check out the cycle plugin, it's great. Might not be exactly what you're looking for but it has some very nice features.

查看循环插件,这很棒。可能不是你想要的,但它有一些非常好的功能。

http://www.malsup.com/jquery/cycle/

http://www.malsup.com/jquery/cycle/