0
<div id="lifecycleStage">
<div id="private2">
    <input type="radio" name="lifecyclePrivate" value="preliminary"         id="preliminary"/>      <label for="preliminary">Preliminary</label>
    <input type="radio" name="lifecyclePrivate" value="prelist"             id="prelist"/>          <label for="prelist">Prelist</label>            
    <input type="radio" name="lifecyclePrivate" value="retired"             id="retired"/>          <label for="retired">Retired</label> <br>           
    <input type="radio" name="lifecyclePrivate" value="internal product"    id="internalProduct"/>  <label for="internalProduct">Internal Product</label>   
    <input type="radio" name="lifecyclePrivate" value="reference nop"       id="referenceNOP"/>     <label for="referenceNOP">Reference NOP</label>     
</div>
<div id="public">
    <input type="radio" name="lifecyclePublic" value="listed"               id="listed"/>           <label for="listed">Listed  ................</label>             
    <input type="radio" name="lifecyclePublic" value="approaching op"       id="approachingOP"/>    <label for="approachingOP">Approaching OP</label>      
    <input type="radio" name="lifecyclePublic" value="no longer available"  id="noLongerAvailable"/><label for="noLongerAvailable">No Longer Available</label> 
</div>

我想要的是将所选标签的背景更改为不同的“独特”颜色。Example when prelist is selected, it has a blue background, but when retired is selected it has a black background.

任何提示和技巧,非常感谢!

4

2 回答 2

2
$('label').on('click',function() {
    $('label').removeClass('active');
    $(this).addClass('active');
});

演示:http: //jsfiddle.net/hpU6k/

于 2013-03-04T20:30:31.473 回答
2

为什么要使用 jQuery?只需使用 CSS:

label {
    background-color: #000;
}

input[type=radio]:checked + label {
    background-color: #00f;
}

JS 小提琴演示

于 2013-03-04T20:34:19.363 回答