2011-03-22 61 views
2

我想在同一个jQuery中使用.fadeIn().fadeOut()两个不同的函数。淡入淡出jQuery中?

对于实例:想象一下,一个形式

假设下面是单选按钮:

Ø美国 - 如果我选择美国,它淡入 - 城市/省份在美国 ØCanada.-如果让我选择加拿大它淡入 - 城市/省份在美国

另一个单选按钮://还有这和上面的单选按钮(美国,加拿大)

岁男之间没有关系 - 它应fadeIn酒吧,酒吧等 O女 - 它应该消退在商场,水疗中心等

我怎么能在jquery?

+1

请邮寄样品在http://jsfiddle.net – felixsigl 2011-03-22 13:11:11

+0

HTML代码,所以,你要知道如何使用淡出和jQuery的淡入?我没有得到并发症。 – 2011-03-22 13:11:45

回答

2

jsFiddle Demo

如果我深知,这应该符合您的需求。

HTML

<input type="checkbox" id="group1Switch" value="group1" /><label for="group1Switch">group 1</label> 
&nbsp;&nbsp;&nbsp; 
<input type="checkbox" id="group2Switch" value="group2" /><label for="group2Switch">group 2</label> 
<br /><br /> 
<input type="radio" name="fieldSwitch" id="type1Switch" value="type1" /><label for="type1Switch">type 1</label> 
&nbsp;&nbsp;&nbsp; 
<input type="radio" name="fieldSwitch" id="type1Switch" value="type2" /><label for="type1Switch">type 2</label> 

<br /><br /> 

<fieldset id="group1"> 
    <legend>Group 1</legend> 
    type 1 <input type="text" class="type1" /> 
    <br /> 
    type 2 <input type="text" class="type2" /> 
</fieldset> 
<fieldset id="group2"> 
    <legend>Group 2</legend> 
    type 1 <input type="text" class="type1" /> 
    <br /> 
    type 2 <input type="text" class="type2" /> 
</fieldset> 

jQuery的

$('input[type=checkbox]').click(function(){ 
    var _this = $(this); 

    if(_this.is(':checked')){ 
     $('#' + _this.val()).fadeIn(); 
    } else { 
     $('#' + _this.val()).fadeOut(); 
    } 
}); 


$('input[type=radio]').click(function(){ 
    var _this = $(this); 

    $('fieldset input.' + _this.val()).fadeIn(); 
    $('fieldset input:not(.' + _this.val() +')').fadeOut(); 
}); 
+0

我没有使用任何复选框。都是单选按钮。我看到你的网站,并试图通过单选按钮进行修改,但不工作。你能检查我吗? – software 2011-03-22 14:13:37

+0

更新了演示,仅使用单选按钮 – GMO 2011-03-22 15:25:15