简体   繁体   English

启用一个无线电组的单选按钮,并在选中时禁用另一个无线电组

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

I want to enable topping only after Pizza is selected I want to either disable topping or from appearing before pizza is 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>

function I am using to check if the radio button is checked or not should I do the for loop to check with if one of the radio buttons is checked from pizza ?? 我用来检查单选按钮是否被检查的功能我是否应该进行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';
    }
}

Here is something you may try: DEMO FIDDLE 这是你可以尝试的东西: 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>

Note: I have Added classes to your input type radio. 注意:我已经为您的输入类型无线电添加了类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基于单选按钮禁用/启用复选框组 - Disable/enable group of checkbox based on radio button 禁用单选按钮组中的按钮 - Disable a button in a radio button group jQuery addClass 当组中的单选按钮被选中时 - jQuery addClass when a radio button in a group is selected 如果已选择一个单选按钮,如何禁用一组单选按钮,如果未选择一个单选按钮并单击下一个按钮,如何显示警报 - How to disable a group of radio buttons if one has been selected and display an alert if one is not selected and the next button is clicked 在单选按钮组中,如何使其中两个启用一个文本框,而其中一个禁用/只读该文本框 - In radio button group, how can I make 2 of them enable a textbox and one of them disable/readonly the textbox 选择下拉菜单上的启用/禁用单选按钮? - Enable/Disable Radio button on dropdown selected? 找出是否在单选按钮组中选择了单选按钮 - Finding out wether a Radio Button was Selected in a Radio Button-Group 从单选按钮中选择特定日期时启用禁用设置单选按钮 - Enable disable set radio button when particular date is selected from radio button 禁用提交按钮,直到选中一组动态创建的单选按钮中的一个 - Disable submit button until one in a group of dynamically-created radio buttons selected 如何检测是否已使用jQuery选择了组中的一个单选按钮 - How to detect if a one radio button in a group has been selected with jQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM