对于第二个问题,您需要将块的输入包装到单独的包装器中并更改一些代码..
JS
$(document).ready(function(){
$('input:radio').change(function(){
var $this = $(this);
// Only remove the class in the specific `box` that contains the radio
$this.closest('.box').find('div.highlight').removeClass('highlight');
$this.closest('.q').addClass('highlight');
});
});
HTML
<div class="box"> 1st set
<div class="q">
<input type="radio" id="1" name="11" />
<label for 1>a</label>
</div>
<div class="q">
<input type="radio" id="2" name="11" />
<label for 2>b</label>
</div>
</div>
<div class="box">
<hr> 2nd set
<div class="q">
<input type="radio" id="3" name="22" />
<label for 3>a</label>
</div>
<div class="q">
<input type="radio" id="4" name="22" />
<label for 4>b</label>
</div>
</div>
检查小提琴