2017-10-18 41 views
0

關於自舉4:自舉4貝塔:檢查哪個上BTN-組項被選中

我有個BTN-組三個單選按鈕,其中一個是預先選定的上頁的負荷。我想根據所選按鈕做一些操作 - 但我無法完成。

這是到目前爲止我的代碼:

<div class="btn-group btn-group-sm mb-2" id="container__Direction" role="group" data-toggle="buttons"> 

    <label class="btn btn-group-btn active"> 
    <input type="radio" data-toggle="button" id="input__Direction_Return" checked /> &lt;--&gt; Return 
    </label> 
    <label class="btn btn-group-btn"> 
    <input type="radio" data-toggle="button" id="input__Direction_OneWay" /> --&gt; One way 
    </label> 
    <label class="btn btn-group-btn"> 
    <input type="radio" data-toggle="button" id="input__Direction_MultiStop" /> -&gt;-&gt; Multi Stop 
    </label> 

</div> 

<!-- Hide this Div if "OneWay" is selected -->  
<div id="container__Inbound_Date"> 
    <label for="input__Date">Date:</label><br/> 
    <input type="date" id="input__Date" /> 
</div> 


$('#input__Direction_OneWay').on('click', function() { 
    if ($(this).is(':checked')) { 
     $("#container__Inbound_Date").hide(); 
    } 
}); 

小提琴:https://jsfiddle.net/SchweizerSchoggi/ax85208e/2/

的BTN-組下面的事業部時,應BTN 「單向」 隱藏被選中。

回答

1

您需要爲所有單選按鈕添加name屬性(即相同)。然後使用change()而不是on('click')

$('input[name=YourName]').change(function() { 
if ($(this).attr('id') == 'input__Direction_OneWay') { 
    $("#container__Inbound_Date").hide(); 
    } 
}); 
+0

,就像一個魅力 - 感謝花費你的時間在這! – SchweizerSchoggi

0

您可以在jQuery中使用類似如下

$(".btn").first().button("toggle"); 

,你可以在下面的代碼中使用點擊事件很好地描述

$(document).on("click", "#input__Direction_OneWay", function() { 
    alert("Goodbye!"); 
}); 
相關問題