使用按钮检查两个或多个无线电组
use buttons to check two or more radio groups
我希望有人能帮助我,因为我已经寻找了一个解决方案,并尝试了许多不同的事情-我卡住了!
这个小提琴也可以演示
我的代码是$("#button_1").click(function() {
$("INPUT[name=type]").val(['1']);
});
$("#button_2").click(function() {
$("INPUT[name=type]").val(['2']);
});
$("#button_3").click(function() {
$("INPUT[name=type]").val(['3']);
});
<button id="button_1">check both blue radios</button>
<button id="button_2">check both red radios</button>
<button id="button_3">check both yellow radios</button>
<br>
<br>
<div id='type'>
<label for="radio_1">blue dial</label>
<input type='radio' id='radio_1' name='type' value='1' />
<label for="radio_2">red dial</label>
<input type='radio' id='radio_2' name='type' value='2' />
<label for="radio_3">yellow dial</label>
<input type='radio' id='radio_3' name='type' value='3' />
</div>
<br>
<br>
<div id='type'>
<label for="radio_1">blue strap</label>
<input type='radio' id='radio_1' name='type' value='1' />
<label for="radio_2">red strap</label>
<input type='radio' id='radio_2' name='type' value='2' />
<label for="radio_3">yellow strap</label>
<input type='radio' id='radio_3' name='type' value='3' />
</div>
我要做的是点击一个按钮并检查下面相关的两个单选按钮。
我是新来的,所以任何帮助都会很感激-谢谢!
试试这个可能会解决你的问题:-
<form>
<fieldset id="group1">
<input type="radio" value="" name="group1">
<input type="radio" value="" name="group1">
</fieldset>
<fieldset id="group2">
<input type="radio" value="" name="group2">
<input type="radio" value="" name="group2">
<input type="radio" value="" name="group2">
</fieldset>
</form>
问题是您的输入具有相同的name属性。
顺便说一下,我改变了另外两个东西:
-
ID属性ID属性必须唯一!即使你不使用它
-
用户使用jQuery
.prop()
函数设置/取消checked
属性$("#button_1").click(function() { $('input[value="1"]').prop('checked', true); }); $("#button_2").click(function() { $('input[value="2"]').prop('checked', true); }); $("#button_3").click(function() { $('input[value="3"]').prop('checked', true); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="button_1">check both blue radios</button> <button id="button_2">check both red radios</button> <button id="button_3">check both yellow radios</button> <br> <br> <div id='type'> <label for="dial_1">blue dial</label> <input type='radio' id='dial_1' name='dial' value='1' /> <label for="dial_2">red dial</label> <input type='radio' id='dial_2' name='dial' value='2' /> <label for="dial_3">yellow dial</label> <input type='radio' id='dial_3' name='dial' value='3' /> </div> <br> <br> <div id='type'> <label for="strap_1">blue strap</label> <input type='radio' id='strap_1' name='strap' value='1' /> <label for="strap_2">red strap</label> <input type='radio' id='strap_2' name='strap' value='2' /> <label for="strap_3">yellow strap</label> <input type='radio' id='strap_3' name='strap' value='3' /> </div>
相关文章:
- JQuery合并了keyup和focusout两个函数
- 如何使用 node.js 比较两个 json 数组
- 为复选框javascript指定两个值
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 单击时切换两个图像
- 我可以'我似乎不知道如何修复javascript中的两个lint.有人能帮我理解吗
- 基于两个条件退出While循环
- 如何在这里将两个值最低的数字相加
- 组合两个javascript函数
- 如何使用offer/answer交换来自两个对等连接的流
- jsf中两个字符串的颜色代码差异
- 加载两个具有相同父密钥名称的json文件
- 在Qualtrics中,介绍如何动态连接两个滑块
- 访问$.ajax()函数中的两个不同数组
- 如何在three.js上添加两个向量
- 如何在datetimepicker中使用两个验证器
- 如何在javascript中获取两个日期之间的周六和周日的日期
- jQuery识别页面加载上的单选按钮的不正确状态,当单选值=“0”时;否”;并且两个无线电都没有被选择
- 使用按钮检查两个或多个无线电组
- 比较两个输入的无线电值