[英]Radio button to check all boxes
<table class="table borderless">
<thead>
<tr>
<th>Rank</th>
<th>+/-</th>
<th>Searches</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="radio" name="optradio" class="custom"> ALL</td>
<td><input type="radio" name="optradio" class="custom"> ALL</td>
<td><input type="radio" name="optradio" class="custom"> ALL</td>
<td><input id="ex2" type="text" class="span2" value="" data-slider-min="10" data-slider-max="1000" data-slider-step="1" data-slider-value="[0,1000]" data-slider-id="RC" id="R"/></td>
</tr>
<tr>
<td><input type="checkbox" class="custom-selector"> Rank 1-10</td>
<td><input type="checkbox" > Up</td>
<td><input type="checkbox" > Over</td>
</tr>
<tr>
<td><input type="checkbox" class="custom-selector"> Rank 11-20</td>
<td><input type="checkbox" > Down</td>
<td><input type="checkbox" > Under</td>
</tr>
<tr>
<td><input type="checkbox" class="custom-selector"> Rank 21-100</td>
<td><input type="checkbox" > No movement</td>
</tr>
<tr>
<td><input type="checkbox" class="custom-selector"> Not in top 100</td>
</tr>
</tbody>
</table>
脚本:
$(document).ready(function () {
$(".custom").change(function () {
$(".custom").parent().find(".custom-selector").prop("checked", true);
})
});
我需要的是一个单选按钮,选中该复选框时会选中所有复选框。
现在,当我单击单选按钮时,什么也没有发生。 但是,如果我添加此单选按钮:
<input type="radio" id="op5" value="1" name="options2" class="custom">
然后他们都工作。 即使是最初的一个,也会选中所有框。
这是什么奇怪的行为? 我想念一些东西
编辑:看来单选按钮必须在桌子外面? 我可以把它放在里面吗?
尝试:
$(".custom").closest("tbody").find(".custom-selector").prop("checked", true);
要不就:
$(".custom-selector").prop("checked", true);
尝试这个:
$(".custom").change(function () {
$(this).parents('tbody').find(".custom-selector:checked");
});
和一些参考: https : //api.jquery.com/checked-selector
最终使用.not(this)
删除操作选择器
尝试这个 :
$(document).ready(function () {
$(".custom").change(function () {
$(".custom-selector").prop("checked", true);
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.