[英]Toggle multiple divs with one button
I´m trying to "toggle" multiple divs with just 2 buttons (one for SHOW and the other for HIDE ) in relation to the last div showed by the function, with SHOW and HIDE 我试图相对于该功能显示的最后一个div,仅用2个按钮“切换”多个div(一个用于SHOW ,另一个用于HIDE ),并使用SHOW和HIDE
So, if I click one time (on SHOW), it must display div with class num1. 因此,如果单击一次(在SHOW上),它必须显示num1类的div。 If I click again, div with class num2 until num5.
如果再次单击,将div设置为num2,直到num5。 But, if I click on HIDE, it must hide the last div showed.
但是,如果我单击“隐藏”,它必须隐藏显示的最后一个div。 Is this possible?
这可能吗?
You could try to do it like this: 您可以尝试这样做:
Use an index
to store the last class shown. 使用
index
存储显示的最后一个类。
Everytime you click on the show button increment this index
and then $(".num"+index).show()
this class. 每次单击显示按钮时,此
index
都会递增,然后$(".num"+index).show()
此类。
If you click the hide, do $(".num"+index).hide()
and then decrement the index
如果单击隐藏,请执行
$(".num"+index).hide()
,然后递减index
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.