2013-03-04 147 views
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> 

變化背景jQuery的

我想是到所選標籤的背景更改爲不同的「獨一無二」的色彩。例如,當選擇預選列表時,它具有藍色背景,但選擇退休時,它具有黑色背景。

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

+0

除非顏色是隨機的,否則這可以用純CSS完成。 – cimmanon 2013-03-04 20:30:11

回答

2

爲什麼使用jQuery?只需使用CSS:

label { 
    background-color: #000; 
} 

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

JS Fiddle demo

+0

這是一個免費的小提琴:http://jsfiddle.net/GWZwd/ – cimmanon 2013-03-04 20:34:43

+0

@cimmanon:謝謝,但我已經創建了我自己的;只是在您發表評論時對其進行編輯。 =) – 2013-03-04 20:36:13

+0

好吧,這是偷偷摸摸的你,因爲當你爲我發佈我的答案時,我正在完成我的小提琴! – cimmanon 2013-03-04 20:36:54

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

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