2011-03-22 63 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