簡體   English   中英

啟用一個無線電組的單選按鈕,並在選中時禁用另一個無線電組

[英]To enable Radio button of one radio group and disable the other radio group when selected

我想在選擇Pizza之后啟用頂部我想要禁用頂部或在選擇披薩之前出現。

<legend>Choose the pizza wrap type ?</legend>
<div class="control-group">//radio group
<label class="radio">
<input type="radio" name="pizza" id="pizza3"value="3" {% if pizza.rel == 3%}
 checked {% endif %}>
 Vegan
</label><br>
<label class="radio">
<input type="radio" name="pizza" id="pizza2" value="2" {% if pizza.rel == 2 %} 
 checked {% endif %}>
 Vegetarian
</label><br>
<label class="radio">
<input type="radio" name="pizza" id="pizza1" value="1" {% if 
pizza.rel == 1 %} checked {% endif %}>
Non vegetarian
</label><br>
<label class="radio">
<input type="radio" name="pizza" id="pizza0" value="0" {% if 
 pizza.rel == 0 %} checked {% endif %}>
 Halal meat
</label>
<button type="button" class="btn btn-link" id="pizza" onclick="captureSelection()">   
</button>
</div>

<h5>Toppings?</h5>
<div class="control-group">     
<label class="radio">
<input type="radio" name="topping" id="topping3" value="3" {% if topping.top == 3
%} checked {% endif %}>
Vegan 
</label><br>
<label class="radio">
<input type="radio" name="topping" id="topping2" value="2" {% if topping.top == 2 
%} checked {% endif %}>
Veggie
</label><br>
<label class="radio">
<input type="radio" name="topping" id="topping1" value="1" {% if topping.top == 1
%} checked {% endif %}>
Meat
</label><br>
<label class="radio">
<input type="radio" name="topping" id="topping0" value="0" {% if topping.top == 0 
%} checked {% endif %}>
Halal meat
</label>
<button type="button" class="btn btn-link" id="topping" onclick="captureSelection()">  
</button>
</div>

我用來檢查單選按鈕是否被檢查的功能我是否應該進行for循環檢查是否從比薩餅中檢查了一個單選按鈕?

function captureSelection(){ 
    var u = document.getElementById('relevance');
    var t = document.getElementById ('topic');
    if (u.value=='unchecked' && u.value ==''){
        t.disable='true';
    }
    else (u.value=='checked'){
        t.enable='true';
    }
}

這是你可以嘗試的東西: DEMO FIDDLE

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type= "text/javascript">
$(document).ready(function () {
    $(".a").click(function () {
        $(".b").prop('checked', false);
    });
    $(".b").click(function () {
        $(".a").prop('checked', false);
    });
});
</script>

注意:我已經為您的輸入類型無線電添加了類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM