我有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/
更多推荐
发布评论