2013-03-01 28 views
0

我有一個表格,我想提供3個選項來支付一個事件。每個選項都是一個單選按鈕,幷包含一個包含付款明細的div。我想隱藏這些div直到選中一個單選按鈕。我如何啓用/禁用電臺選擇的div

我創建了一個的jsfiddle與我目前所:http://jsfiddle.net/Kvg8M/1/

此刻,我已設法讓所有3周的div被隱藏,並出現在同一時間,但我想只顯示一個取決於收音機選擇的細節集並隱藏其他。

這裏是JS:

$(document).ready(function() { 
    $(".paymentmethod").click(function() { 
     $(".paymentinfo").show('slow'); 
    }); 
}); 
+0

**授權 – 2013-03-01 02:50:24

+0

感謝您的意見,不同的方式去了解這一點。 – sampotts 2013-03-01 03:34:05

回答

2

看的價值,並顯示相應的DIV。

$(document).ready(function() { 
    $(".paymentmethod").click(function() { 
     $(".paymentinfo").hide(); 
     switch ($(this).val()) { 
      case "Direct Deposit": 
       $("#pay0").show("slow"); 
       break; 
      case "Credit Card Authorisation": 
       $("#pay1").show("slow"); 
       break; 
      case "Cash at FAA Office (In Person)": 
       $("#pay2").show("slow"); 
       break; 
     } 
    }); 
}); 

FIDDLE

2

我會一個data-pay屬性添加到每個輸入等於的id價值<div>你想顯示:

HTML:

<input type="radio" value="Direct Deposit" id="CAT_Custom_249152_0" name="CAT_Custom_249152" class="paymentmethod" data-pay="pay0"/> 
<input type="radio" value="Credit Card Authorisation" id="CAT_Custom_249152_1" class="paymentmethod" name="CAT_Custom_249152" data-pay="pay1"/> 
<input type="radio" value="Cash at FAA Office (In Person)" id="CAT_Custom_249152_2" class="paymentmethod" name="CAT_Custom_249152" data-pay="pay2"/> 

Javascript:

$(document).ready(function() { 
    $(".paymentmethod").click(function() { 
    $('.paymentinfo').hide(); 
    $('#'+$(this).data('pay')).show('slow'); 
    }); 
}); 

FIDDLE