我搜索过了。
这个想法是当选择一个无线电时,它的父标签会改变class =" sample" to class ="选择样本"。
我有。
问题是当我选择其中一个分组的"无线电好友"我需要:
标签类="样本">
<div class="col">
<div class="form-check d-inline">
<input type="radio" name="event_type" class="form-check-input">
Wedding Reception
</div>
</div>
/标签&gt;
$('.sample').click(function() { $(this).addClass('selected'); });
谢谢
答案 0 :(得分:0)
您可以使用方法1或方法2:
方法1 :(来自您的帖子)
$('.sample').click(function() {
// Remove the existing 'selected' class. It will fulfill your first question
$('.sample.selected').removeClass('selected');
// Add the 'selected' class for newly clicked radio button's parent label element. It will fulfill your second question
$(this).addClass('selected');
});
方法2:
$('input[type=radio]').change(function(){
// Remove the existing 'selected' class. It will fulfill your first question
$('label.sample.selected').removeClass('selected');
// Add the 'selected' class for newly clicked radio button's parent label element. It will fulfill your second question
$(this).closest('label.sample').addClass('selected');
});
方法1缺点: