Jquery切换多个div(Jquery toggle multiple div)

编程入门 行业动态 更新时间:2024-10-26 09:19:27
Jquery切换多个div(Jquery toggle multiple div)

我有4个div, abcd ,使用Jquery toggle来打开和关闭,每个都靠近它自己。

还有一个按钮可以关闭并打开所有。

但是,如果用户首先单击“b” ,则单击“全部关闭”按钮。 它会成为。 a,c,d关闭b打开 。 有没有办法让一个按钮hide不是更改功能来show ?

http://jsfiddle.net/vyPHZ/

$(document).ready(function(){ $(".toggle").click(function(){$(this).next("div").slideToggle(300);}); $("#collapse").click( function(){ $(".content").toggle(); } ); });

I have 4 div, a b c d, use Jquery toggle to open and close, each one close by it self.

There is also one button can close and open all.

However if user click 'b' first, than click 'close all' button. it will become. a, c, d close, b open. Is any way to make one button hide than change function to show?

http://jsfiddle.net/vyPHZ/

$(document).ready(function(){ $(".toggle").click(function(){$(this).next("div").slideToggle(300);}); $("#collapse").click( function(){ $(".content").toggle(); } ); });

最满意答案

http://jsfiddle.net/vyPHZ/2/

$(".toggle").click(function () { $(this).next(".content").slideToggle(300); }); var io = 0; $("#collapse").click(function () { $(".content")[io++%2?'show':'hide'](); });

在哪里,如果你愿意,而不是'show':'hide'你可以使用'slideDown':'slideUp' //jsfiddle.net/vyPHZ/3/

http://jsfiddle.net/vyPHZ/2/

$(".toggle").click(function () { $(this).next(".content").slideToggle(300); }); var io = 0; $("#collapse").click(function () { $(".content")[io++%2?'show':'hide'](); });

where also, if you like, instead of 'show':'hide' you can use 'slideDown':'slideUp' http://jsfiddle.net/vyPHZ/3/

更多推荐

本文发布于:2023-07-31 00:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   Jquery   div   multiple   toggle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!