2013-04-28 170 views
1
<div class="form-radios" id="edit-attributes-1"> 
<div class="form-item form-type-radio form-item-attributes-1"> 
<input type="radio" class="form-radio" value="1" name="attributes[1]" id="edit-attributes-1-1"> <label for="edit-attributes-1-1" class="option">0 </label> 

</div> 
<div class="form-item form-type-radio form-item-attributes-1"> 
<input type="radio" class="form-radio" value="2" name="attributes[1]" id="edit-attributes-1-2"> <label for="edit-attributes-1-2" class="option">2 </label> 

</div> 
<div class="form-item form-type-radio form-item-attributes-1"> 
<input type="radio" class="form-radio" value="3" name="attributes[1]" id="edit-attributes-1-3"> <label for="edit-attributes-1-3" class="option">4 </label> 

</div> 
<div class="form-item form-type-radio form-item-attributes-1"> 
<input type="radio" class="form-radio" value="4" name="attributes[1]" id="edit-attributes-1-4"> <label for="edit-attributes-1-4" class="option">6 </label> 

</div> 
<div class="form-item form-type-radio form-item-attributes-1"> 
<input type="radio" class="form-radio" value="5" name="attributes[1]" id="edit-attributes-1-5"> <label for="edit-attributes-1-5" class="option">8 </label> 

</div> 
</div> 

我有這種類型的drupal單選按鈕結構添加到購物車窗體中。我必須在點擊單選按鈕的標籤(不是單選按鈕)上添加「活動」類,並從其他點擊單選按鈕的標籤(不在單選按鈕)上移除「活動」類。請幫忙。添加單選按鈕標籤類

感謝

+0

純CSS解決方案(應該在所有的現代瀏覽器,如果它只是爲了造型的目的):HTTP:/ /jsfiddle.net/2FHKS/1/ – CBroe 2013-04-28 02:37:23

回答

1
$('input[type=radio]').click(function(){ 
    $('label').removeClass('active'); 
    $(this).next('label').addClass('active'); 
}); 

jsFiddle example

+1

感謝您的幫助。 – 2013-04-28 02:41:34

0

試試這個

$(function() { 
    $('.form-radio').on('click', function() { 
     $('.form-radio').each(function() { 
      $(this).next().removeClass('active'); 
     }); 
     if($(this).is(':checked')) 
      $(this).next().addClass('active'); 
    }); 
});