2013-04-29 60 views
0

我想在jQuery中編寫一個函數,它可以識別用戶在我的頁面上選中了一個複選框,然後它知道並實時(它的意思是當用戶選中複選框,然後這個tdcheck-box和一個label標籤是否有改變顏色爲紅色

我需要它,因爲我有一個calendar用戶可以檢查每一天的check box選擇一年的假期天然後我在我的db中保存所有365天的一年。 我創建一個數據列表和克里特表,我有365 <td>它包含<label>< check box > </td>一年中的每一天jQuery函數用於檢查複選框並對其執行操作

我希望能很快幫助我,謝謝。

+1

請告訴我們你到目前爲止已經嘗試了什麼,以及你堅持的具體點。在這裏問一個問題時,代碼幾乎總是需要的。 – ahren 2013-04-29 09:49:20

+0

我不知道這個函數的jquery的編碼,我在谷歌搜索和發現我可以使用更改()列表複選框,但我不知道corectly如何? ()函數(){ $(「CheckBox」)。change(function(){ $(「.ForHolidayChanging」)。((checkbox) 「td」)。css({'background-color':'pink'}); });}); }); - %> – 2013-04-29 09:52:54

+2

然後我建議僱人來幫助你。 Stackoverflow用於幫助人們遇到困難時不提供免費工作服務。 – ahren 2013-04-29 09:54:39

回答

0
$('#checkbox').click(function(){ 
     if($(this).is(':checked')){ 
     $('#label').css({'background-color':'red'}); 

}

在文件準備功能得到這個代碼

+0

我試試這個代碼,但點擊是不是在實時我閱讀改變方法,我必須檢查365時間,因爲我有365天在一年,爲此我想使用css類,並將其用於我的數據列表,然後我可以說,如果其中一個複選框,在這個datalist檢查用戶的標籤改變顏色爲紅色,但感謝您的答案 – 2013-04-29 10:22:23

0

試試這個:

$('#checkboxid').click(function(){ 
    $(this).closest('td').css('background-color', 'Red'); 

}); 

,或者如果您想更改標籤顏色做到這一點:

$('#checkboxid').click(function(){ 
    $(this).closest('td')find('td:first').css('background-color', 'Red'); 
}); 

write thi在document.ready函數中。

1

親愛嘗試使用下面的代碼

$(function() { 
    $('#CheckBox').click(function() { 
     if($(this).is(':checked')) { 
      $('Lable').css('background-color' , 'red'); 
     } 
    }); 
}); 
0

請對

http://jsfiddle.net/2dJAN/4/

<div class="checkboxes"> 
    <input type="checkbox" name="1" id="option-one" value="orange"><label for="option-one" class="highlight">1</label> 
    <input type="checkbox" name="2" id="option-two" value="apple"><label for="option-two" class="highlight">2</label> 
     <input type="checkbox" name="2" id="option-three" value="apple"><label for="option-three" class="highlight">3</label> 
</div> 

.checkboxes label { 
    font-family:Open Sans Italic; 
    font-size: 12px; 
    color: #666; 
    border-radius: 20px 20px 20px 20px; 
    background: #f0f0f0; 
    padding: 3px 10px; 
    text-align: left; 
} 
input[type=checkbox]:checked + label { 
    color: white; 
    background: #86b3c1; 
} 

看看正在努力實現這個樣子?