我需要取消选中具有相同类的其他单选按钮(当然它们不在同一组中)

  • 本文关键字:一组 单选按钮 取消 其他 同类 jquery
  • 更新时间 :
  • 英文 :


当我选中单选按钮时,我需要取消选中使用兄弟姐妹持有相同类的其他单选按钮(当然它们不在同一组中(。因此,当我单击收音机时,不同组中的所有其他人都必须取消选中 我该怎么做?`

$('.RRFrom').click(function(){
$(this).siblings().prop('checked', false);
});

'

<div class="form-check form-check-inline ml-4">
<input class="form-check-input  RRFrom RRFromRow2" type="radio" name="RRZZFromRow2[]" id="RRFromRow2" value="RR" style="cursor:pointer">
<label for="RRFromRow2" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer">Rail Road</label>
</div>
<div class="form-check form-check-inline ml-4 ">
<input class="form-check-input ChassiFromRow2" type="radio" name="RRZZFromRow2[]" id="ChassiFromRow2" value="ZZ" style="cursor:pointer">
<label for="ChassiFromRow2" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer" >Chassi</label>
</div>
<div class="form-check form-check-inline ml-4">
<input class="form-check-input  RRFrom RRFromRow1  " type="radio" name="RRZZFromRow1[]" id="RRFromRow1" value="RR" style="cursor:pointer">
<label for="RRFromRow1" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer">Rail Road</label>
</div>
<div class="form-check form-check-inline ml-4 ">
<input class="form-check-input ChassiFromRow1" type="radio" name="RRZZFromRow1[]" id="ChassiFromRow1" value="ZZ" style="cursor:pointer">
<label for="ChassiFromRow1" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer" >Chassi</label>
</div>

//.html

请注意:其他类。RRFrom 不在同一个组中,实际上它们也在不同的div 中,但拥有相同的类名。

另外,请不要使用removeAttr((,因为这不允许我再次检查单选按钮!!

只需选择类,不包括带有.not(this)的单击元素

工作片段:

$('.RRFrom').click(function(){
$('.RRFrom').not(this).prop('checked', false);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-check form-check-inline ml-4">
<input class="form-check-input  RRFrom RRFromRow2" type="radio" name="RRZZFromRow2[]" id="RRFromRow2" value="RR" style="cursor:pointer">
<label for="RRFromRow2" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer">Rail Road</label>
</div>
<div class="form-check form-check-inline ml-4 ">
<input class="form-check-input ChassiFromRow2" type="radio" name="RRZZFromRow2[]" id="ChassiFromRow2" value="ZZ" style="cursor:pointer">
<label for="ChassiFromRow2" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer" >Chassi</label>
</div>
<div class="form-check form-check-inline ml-4">
<input class="form-check-input  RRFrom RRFromRow1  " type="radio" name="RRZZFromRow1[]" id="RRFromRow1" value="RR" style="cursor:pointer">
<label for="RRFromRow1" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer">Rail Road</label>
</div>
<div class="form-check form-check-inline ml-4 ">
<input class="form-check-input ChassiFromRow1" type="radio" name="RRZZFromRow1[]" id="ChassiFromRow1" value="ZZ" style="cursor:pointer">
<label for="ChassiFromRow1" class="form-check-label col-form-label col-form-label-sm" style="cursor:pointer" >Chassi</label>
</div>

最新更新