Javascript 3复选框1独立于其他复选框,jquery不需要将第一个复选框视为集合的一部分
我写了一个问题,在他们改变主意之前,答案确实满足了业务要求 这段代码非常有效Javascript 3复选框1独立于其他复选框,jquery不需要将第一个复选框视为集合的一部分,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我写了一个问题,在他们改变主意之前,答案确实满足了业务要求 这段代码非常有效 $('input[type="checkbox"]').on('change', function () { $(this).closest('tr').find('input[type="checkbox"]').not(this).prop('checked', false); }); 上述代码确实满足了当时的业务需求 必须只允许选中3个框中的1个。出去,是的,不是 必须允许再次单击复选框以取消
$('input[type="checkbox"]').on('change', function () {
$(this).closest('tr').find('input[type="checkbox"]').not(this).prop('checked', false);
});
上述代码确实满足了当时的业务需求
<table>
<tr>
<td>
<input id="GridView1__ctl2_chkOut" type="checkbox" name="GridView1:_ctl2:chkOut" checked="checked">
</td>
<td>
<input id="GridView1__ctl2_chkYes2" type="checkbox" name="GridView1:_ctl2:chkYes2">
</td>
<td>
<input id="GridView1__ctl2_chkNo2" type="checkbox" name="GridView1:_ctl2:chkNo2">
</td>
</tr>
</table>
似乎逻辑现在变得复杂了,因为不能简单地查看下一个tr标记中最近的复选框。您可以在每个复选框中添加一个类或id(如果有多行,则为类),然后使用两个更改函数来实现您的结果:
在上面的示例中,可以根据您的要求同时选中“是”和“是”复选框,或者同时选中“是”和“否”。你也可以取消选中这三个选项中的任何一个。是的,这很好,我给了你荣誉,尽管OP的答案他确实让它像它想要的那样工作。谢谢
$('input[type="checkbox"]').on('change', function () {
// if checkbox equals ^Out ... Do allow for it to be checked if
//the yes or no is checked , and if checked, toggle to unchecked if clicked on
$(this).closest('tr').find('input[type="checkbox"]').not(this).prop('checked', false);
});
$('.no').on('change', function () {
$(this).closest('tr').find('.out').not(this).prop('checked', false);
});
$('.out').on('change', function () {
$(this).closest('tr').find('.no').not(this).prop('checked', false);
});